1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/uriloader/exthandler/nsContentHandlerApp.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * vim:expandtab:shiftwidth=2:tabstop=2:cin: 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "nsContentHandlerApp.h" 1.11 +#include "nsIURI.h" 1.12 +#include "nsIClassInfoImpl.h" 1.13 +#include "nsCOMPtr.h" 1.14 +#include "nsString.h" 1.15 + 1.16 +#define NS_CONTENTHANDLER_CID \ 1.17 +{ 0x43ec2c82, 0xb9db, 0x4835, {0x80, 0x3f, 0x64, 0xc9, 0x72, 0x5a, 0x70, 0x28 } } 1.18 + 1.19 +NS_IMPL_CLASSINFO(nsContentHandlerApp, nullptr, 0, NS_CONTENTHANDLER_CID) 1.20 +NS_IMPL_ISUPPORTS_CI(nsContentHandlerApp, nsIHandlerApp) 1.21 + 1.22 +nsContentHandlerApp::nsContentHandlerApp(nsString aName, nsCString aType, 1.23 + ContentAction::Action& aAction) : 1.24 + mName(aName), 1.25 + mType(aType), 1.26 + mAction(aAction) 1.27 +{ 1.28 +} 1.29 + 1.30 +//////////////////////////////////////////////////////////////////////////////// 1.31 +//// nsIHandlerInfo 1.32 + 1.33 +NS_IMETHODIMP nsContentHandlerApp::GetName(nsAString& aName) 1.34 +{ 1.35 + aName.Assign(mName); 1.36 + return NS_OK; 1.37 +} 1.38 + 1.39 +NS_IMETHODIMP nsContentHandlerApp::SetName(const nsAString& aName) 1.40 +{ 1.41 + mName.Assign(aName); 1.42 + return NS_OK; 1.43 +} 1.44 + 1.45 +NS_IMETHODIMP nsContentHandlerApp::Equals(nsIHandlerApp *aHandlerApp, bool *_retval) 1.46 +{ 1.47 + return NS_ERROR_NOT_IMPLEMENTED; 1.48 +} 1.49 + 1.50 +NS_IMETHODIMP nsContentHandlerApp::GetDetailedDescription(nsAString& aDetailedDescription) 1.51 +{ 1.52 + aDetailedDescription.Assign(mDetailedDescription); 1.53 + return NS_OK; 1.54 +} 1.55 + 1.56 +NS_IMETHODIMP nsContentHandlerApp::SetDetailedDescription(const nsAString& aDetailedDescription) 1.57 +{ 1.58 + mDetailedDescription.Assign(aDetailedDescription); 1.59 + return NS_OK; 1.60 +} 1.61 + 1.62 +NS_IMETHODIMP 1.63 +nsContentHandlerApp::LaunchWithURI(nsIURI *aURI, 1.64 + nsIInterfaceRequestor *aWindowContext) 1.65 +{ 1.66 + nsAutoCString spec; 1.67 + nsresult rv = aURI->GetAsciiSpec(spec); 1.68 + NS_ENSURE_SUCCESS(rv,rv); 1.69 + const char* url = spec.get(); 1.70 + 1.71 + QList<ContentAction::Action> actions = 1.72 + ContentAction::Action::actionsForFile(QUrl(url), QString(mType.get())); 1.73 + for (int i = 0; i < actions.size(); ++i) { 1.74 + if (actions[i].name() == QString((QChar*)mName.get(), mName.Length())) { 1.75 + actions[i].trigger(); 1.76 + break; 1.77 + } 1.78 + } 1.79 + 1.80 + return NS_OK; 1.81 +} 1.82 +