michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim:expandtab:shiftwidth=2:tabstop=2:cin: michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsContentHandlerApp.h" michael@0: #include "nsIURI.h" michael@0: #include "nsIClassInfoImpl.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsString.h" michael@0: michael@0: #define NS_CONTENTHANDLER_CID \ michael@0: { 0x43ec2c82, 0xb9db, 0x4835, {0x80, 0x3f, 0x64, 0xc9, 0x72, 0x5a, 0x70, 0x28 } } michael@0: michael@0: NS_IMPL_CLASSINFO(nsContentHandlerApp, nullptr, 0, NS_CONTENTHANDLER_CID) michael@0: NS_IMPL_ISUPPORTS_CI(nsContentHandlerApp, nsIHandlerApp) michael@0: michael@0: nsContentHandlerApp::nsContentHandlerApp(nsString aName, nsCString aType, michael@0: ContentAction::Action& aAction) : michael@0: mName(aName), michael@0: mType(aType), michael@0: mAction(aAction) michael@0: { michael@0: } michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// nsIHandlerInfo michael@0: michael@0: NS_IMETHODIMP nsContentHandlerApp::GetName(nsAString& aName) michael@0: { michael@0: aName.Assign(mName); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentHandlerApp::SetName(const nsAString& aName) michael@0: { michael@0: mName.Assign(aName); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentHandlerApp::Equals(nsIHandlerApp *aHandlerApp, bool *_retval) michael@0: { michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentHandlerApp::GetDetailedDescription(nsAString& aDetailedDescription) michael@0: { michael@0: aDetailedDescription.Assign(mDetailedDescription); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentHandlerApp::SetDetailedDescription(const nsAString& aDetailedDescription) michael@0: { michael@0: mDetailedDescription.Assign(aDetailedDescription); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsContentHandlerApp::LaunchWithURI(nsIURI *aURI, michael@0: nsIInterfaceRequestor *aWindowContext) michael@0: { michael@0: nsAutoCString spec; michael@0: nsresult rv = aURI->GetAsciiSpec(spec); michael@0: NS_ENSURE_SUCCESS(rv,rv); michael@0: const char* url = spec.get(); michael@0: michael@0: QList actions = michael@0: ContentAction::Action::actionsForFile(QUrl(url), QString(mType.get())); michael@0: for (int i = 0; i < actions.size(); ++i) { michael@0: if (actions[i].name() == QString((QChar*)mName.get(), mName.Length())) { michael@0: actions[i].trigger(); michael@0: break; michael@0: } michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: