OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/guest_view/extension_options/extension_options_guest.h" | 5 #include "chrome/browser/guest_view/extension_options/extension_options_guest.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 8 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
9 #include "chrome/browser/extensions/extension_tab_util.h" | 9 #include "chrome/browser/extensions/extension_tab_util.h" |
10 #include "chrome/browser/guest_view/extension_options/extension_options_constant
s.h" | 10 #include "chrome/browser/guest_view/extension_options/extension_options_constant
s.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/task_manager/task_manager_util.h" |
12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_finder.h" | 14 #include "chrome/browser/ui/browser_finder.h" |
14 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
16 #include "chrome/common/extensions/api/extension_options_internal.h" | 17 #include "chrome/common/extensions/api/extension_options_internal.h" |
17 #include "chrome/common/extensions/manifest_url_handler.h" | 18 #include "chrome/common/extensions/manifest_url_handler.h" |
| 19 #include "chrome/grit/generated_resources.h" |
18 #include "components/crx_file/id_util.h" | 20 #include "components/crx_file/id_util.h" |
19 #include "content/public/browser/render_process_host.h" | 21 #include "content/public/browser/render_process_host.h" |
20 #include "content/public/browser/site_instance.h" | 22 #include "content/public/browser/site_instance.h" |
21 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
22 #include "extensions/browser/extension_function_dispatcher.h" | 24 #include "extensions/browser/extension_function_dispatcher.h" |
23 #include "extensions/browser/extension_registry.h" | 25 #include "extensions/browser/extension_registry.h" |
24 #include "extensions/browser/guest_view/guest_view_manager.h" | 26 #include "extensions/browser/guest_view/guest_view_manager.h" |
25 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
26 #include "extensions/common/extension_messages.h" | 28 #include "extensions/common/extension_messages.h" |
27 #include "extensions/common/feature_switch.h" | 29 #include "extensions/common/feature_switch.h" |
28 #include "extensions/common/permissions/permissions_data.h" | 30 #include "extensions/common/permissions/permissions_data.h" |
29 #include "ipc/ipc_message_macros.h" | 31 #include "ipc/ipc_message_macros.h" |
| 32 #include "ui/base/l10n/l10n_util.h" |
30 | 33 |
31 using content::WebContents; | 34 using content::WebContents; |
32 using namespace extensions::api; | 35 using namespace extensions::api; |
33 | 36 |
34 // static | 37 // static |
35 const char ExtensionOptionsGuest::Type[] = "extensionoptions"; | 38 const char ExtensionOptionsGuest::Type[] = "extensionoptions"; |
36 | 39 |
37 ExtensionOptionsGuest::ExtensionOptionsGuest( | 40 ExtensionOptionsGuest::ExtensionOptionsGuest( |
38 content::BrowserContext* browser_context, | 41 content::BrowserContext* browser_context, |
39 int guest_instance_id) | 42 int guest_instance_id) |
40 : GuestView<ExtensionOptionsGuest>(browser_context, guest_instance_id) { | 43 : GuestView<ExtensionOptionsGuest>(browser_context, guest_instance_id) { |
41 } | 44 } |
42 | 45 |
43 ExtensionOptionsGuest::~ExtensionOptionsGuest() { | 46 ExtensionOptionsGuest::~ExtensionOptionsGuest() { |
44 } | 47 } |
45 | 48 |
46 const char* ExtensionOptionsGuest::GetAPINamespace() { | |
47 return extensionoptions::kAPINamespace; | |
48 } | |
49 | |
50 // static | 49 // static |
51 extensions::GuestViewBase* ExtensionOptionsGuest::Create( | 50 extensions::GuestViewBase* ExtensionOptionsGuest::Create( |
52 content::BrowserContext* browser_context, | 51 content::BrowserContext* browser_context, |
53 int guest_instance_id) { | 52 int guest_instance_id) { |
54 if (!extensions::FeatureSwitch::embedded_extension_options()->IsEnabled()) { | 53 if (!extensions::FeatureSwitch::embedded_extension_options()->IsEnabled()) { |
55 return NULL; | 54 return NULL; |
56 } | 55 } |
57 return new ExtensionOptionsGuest(browser_context, guest_instance_id); | 56 return new ExtensionOptionsGuest(browser_context, guest_instance_id); |
58 } | 57 } |
59 | 58 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 guest_web_contents()); | 120 guest_web_contents()); |
122 } | 121 } |
123 | 122 |
124 void ExtensionOptionsGuest::DidStopLoading() { | 123 void ExtensionOptionsGuest::DidStopLoading() { |
125 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 124 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
126 DispatchEventToEmbedder(new extensions::GuestViewBase::Event( | 125 DispatchEventToEmbedder(new extensions::GuestViewBase::Event( |
127 extensions::api::extension_options_internal::OnLoad::kEventName, | 126 extensions::api::extension_options_internal::OnLoad::kEventName, |
128 args.Pass())); | 127 args.Pass())); |
129 } | 128 } |
130 | 129 |
| 130 const char* ExtensionOptionsGuest::GetAPINamespace() const { |
| 131 return extensionoptions::kAPINamespace; |
| 132 } |
| 133 |
| 134 base::string16 ExtensionOptionsGuest::GetTaskName() const { |
| 135 const int message_id = IDS_TASK_MANAGER_EXTENSIONOPTIONS_TAG_PREFIX; |
| 136 base::string16 title = |
| 137 task_manager::util::GetTitleFromWebContents(guest_web_contents()); |
| 138 return l10n_util::GetStringFUTF16(message_id, title); |
| 139 } |
| 140 |
131 content::WebContents* ExtensionOptionsGuest::GetAssociatedWebContents() const { | 141 content::WebContents* ExtensionOptionsGuest::GetAssociatedWebContents() const { |
132 return guest_web_contents(); | 142 return guest_web_contents(); |
133 } | 143 } |
134 | 144 |
135 bool ExtensionOptionsGuest::OnMessageReceived(const IPC::Message& message) { | 145 bool ExtensionOptionsGuest::OnMessageReceived(const IPC::Message& message) { |
136 bool handled = true; | 146 bool handled = true; |
137 IPC_BEGIN_MESSAGE_MAP(ExtensionOptionsGuest, message) | 147 IPC_BEGIN_MESSAGE_MAP(ExtensionOptionsGuest, message) |
138 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | 148 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
139 IPC_MESSAGE_UNHANDLED(handled = false) | 149 IPC_MESSAGE_UNHANDLED(handled = false) |
140 IPC_END_MESSAGE_MAP() | 150 IPC_END_MESSAGE_MAP() |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 content::OpenURLParams params(target_url, | 213 content::OpenURLParams params(target_url, |
204 content::Referrer(), | 214 content::Referrer(), |
205 NEW_FOREGROUND_TAB, | 215 NEW_FOREGROUND_TAB, |
206 content::PAGE_TRANSITION_LINK, | 216 content::PAGE_TRANSITION_LINK, |
207 false); | 217 false); |
208 browser->OpenURL(params); | 218 browser->OpenURL(params); |
209 // TODO(ericzeng): Open the tab in the background if the click was a | 219 // TODO(ericzeng): Open the tab in the background if the click was a |
210 // ctrl-click or middle mouse button click | 220 // ctrl-click or middle mouse button click |
211 return false; | 221 return false; |
212 } | 222 } |
OLD | NEW |