|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * vim:expandtab:shiftwidth=2:tabstop=2:cin: |
|
3 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #include "nsContentHandlerApp.h" |
|
8 #include "nsIURI.h" |
|
9 #include "nsIClassInfoImpl.h" |
|
10 #include "nsCOMPtr.h" |
|
11 #include "nsString.h" |
|
12 |
|
13 #define NS_CONTENTHANDLER_CID \ |
|
14 { 0x43ec2c82, 0xb9db, 0x4835, {0x80, 0x3f, 0x64, 0xc9, 0x72, 0x5a, 0x70, 0x28 } } |
|
15 |
|
16 NS_IMPL_CLASSINFO(nsContentHandlerApp, nullptr, 0, NS_CONTENTHANDLER_CID) |
|
17 NS_IMPL_ISUPPORTS_CI(nsContentHandlerApp, nsIHandlerApp) |
|
18 |
|
19 nsContentHandlerApp::nsContentHandlerApp(nsString aName, nsCString aType, |
|
20 ContentAction::Action& aAction) : |
|
21 mName(aName), |
|
22 mType(aType), |
|
23 mAction(aAction) |
|
24 { |
|
25 } |
|
26 |
|
27 //////////////////////////////////////////////////////////////////////////////// |
|
28 //// nsIHandlerInfo |
|
29 |
|
30 NS_IMETHODIMP nsContentHandlerApp::GetName(nsAString& aName) |
|
31 { |
|
32 aName.Assign(mName); |
|
33 return NS_OK; |
|
34 } |
|
35 |
|
36 NS_IMETHODIMP nsContentHandlerApp::SetName(const nsAString& aName) |
|
37 { |
|
38 mName.Assign(aName); |
|
39 return NS_OK; |
|
40 } |
|
41 |
|
42 NS_IMETHODIMP nsContentHandlerApp::Equals(nsIHandlerApp *aHandlerApp, bool *_retval) |
|
43 { |
|
44 return NS_ERROR_NOT_IMPLEMENTED; |
|
45 } |
|
46 |
|
47 NS_IMETHODIMP nsContentHandlerApp::GetDetailedDescription(nsAString& aDetailedDescription) |
|
48 { |
|
49 aDetailedDescription.Assign(mDetailedDescription); |
|
50 return NS_OK; |
|
51 } |
|
52 |
|
53 NS_IMETHODIMP nsContentHandlerApp::SetDetailedDescription(const nsAString& aDetailedDescription) |
|
54 { |
|
55 mDetailedDescription.Assign(aDetailedDescription); |
|
56 return NS_OK; |
|
57 } |
|
58 |
|
59 NS_IMETHODIMP |
|
60 nsContentHandlerApp::LaunchWithURI(nsIURI *aURI, |
|
61 nsIInterfaceRequestor *aWindowContext) |
|
62 { |
|
63 nsAutoCString spec; |
|
64 nsresult rv = aURI->GetAsciiSpec(spec); |
|
65 NS_ENSURE_SUCCESS(rv,rv); |
|
66 const char* url = spec.get(); |
|
67 |
|
68 QList<ContentAction::Action> actions = |
|
69 ContentAction::Action::actionsForFile(QUrl(url), QString(mType.get())); |
|
70 for (int i = 0; i < actions.size(); ++i) { |
|
71 if (actions[i].name() == QString((QChar*)mName.get(), mName.Length())) { |
|
72 actions[i].trigger(); |
|
73 break; |
|
74 } |
|
75 } |
|
76 |
|
77 return NS_OK; |
|
78 } |
|
79 |