OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/tab_helper.h" | 5 #include "chrome/browser/extensions/tab_helper.h" |
6 | 6 |
7 #include "chrome/browser/extensions/activity_log.h" | 7 #include "chrome/browser/extensions/activity_log.h" |
| 8 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h" |
| 9 #include "chrome/browser/extensions/api/declarative_content/content_rules_regist
ry.h" |
8 #include "chrome/browser/extensions/app_notify_channel_ui.h" | 10 #include "chrome/browser/extensions/app_notify_channel_ui.h" |
9 #include "chrome/browser/extensions/crx_installer.h" | 11 #include "chrome/browser/extensions/crx_installer.h" |
10 #include "chrome/browser/extensions/extension_action.h" | 12 #include "chrome/browser/extensions/extension_action.h" |
11 #include "chrome/browser/extensions/extension_action_manager.h" | 13 #include "chrome/browser/extensions/extension_action_manager.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/extensions/extension_system.h" |
13 #include "chrome/browser/extensions/extension_tab_util.h" | 16 #include "chrome/browser/extensions/extension_tab_util.h" |
14 #include "chrome/browser/extensions/page_action_controller.h" | 17 #include "chrome/browser/extensions/page_action_controller.h" |
15 #include "chrome/browser/extensions/script_badge_controller.h" | 18 #include "chrome/browser/extensions/script_badge_controller.h" |
16 #include "chrome/browser/extensions/script_bubble_controller.h" | 19 #include "chrome/browser/extensions/script_bubble_controller.h" |
17 #include "chrome/browser/extensions/script_executor.h" | 20 #include "chrome/browser/extensions/script_executor.h" |
18 #include "chrome/browser/extensions/webstore_standalone_installer.h" | 21 #include "chrome/browser/extensions/webstore_standalone_installer.h" |
19 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/sessions/session_id.h" | 23 #include "chrome/browser/sessions/session_id.h" |
21 #include "chrome/browser/sessions/session_tab_helper.h" | 24 #include "chrome/browser/sessions/session_tab_helper.h" |
22 #include "chrome/browser/ui/browser_dialogs.h" | 25 #include "chrome/browser/ui/browser_dialogs.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 78 |
76 TabHelper::TabHelper(content::WebContents* web_contents) | 79 TabHelper::TabHelper(content::WebContents* web_contents) |
77 : content::WebContentsObserver(web_contents), | 80 : content::WebContentsObserver(web_contents), |
78 extension_app_(NULL), | 81 extension_app_(NULL), |
79 ALLOW_THIS_IN_INITIALIZER_LIST( | 82 ALLOW_THIS_IN_INITIALIZER_LIST( |
80 extension_function_dispatcher_( | 83 extension_function_dispatcher_( |
81 Profile::FromBrowserContext(web_contents->GetBrowserContext()), | 84 Profile::FromBrowserContext(web_contents->GetBrowserContext()), |
82 this)), | 85 this)), |
83 pending_web_app_action_(NONE), | 86 pending_web_app_action_(NONE), |
84 script_executor_(new ScriptExecutor(web_contents, | 87 script_executor_(new ScriptExecutor(web_contents, |
85 &script_execution_observers_)) { | 88 &script_execution_observers_)), |
| 89 content_rules_registry_( |
| 90 ExtensionSystem::Get( |
| 91 Profile::FromBrowserContext(web_contents->GetBrowserContext()))-> |
| 92 rules_registry_service()->content_rules_registry()) { |
86 // The ActiveTabPermissionManager requires a session ID; ensure this | 93 // The ActiveTabPermissionManager requires a session ID; ensure this |
87 // WebContents has one. | 94 // WebContents has one. |
88 SessionTabHelper::CreateForWebContents(web_contents); | 95 SessionTabHelper::CreateForWebContents(web_contents); |
89 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter( | 96 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter( |
90 web_contents, | 97 web_contents, |
91 SessionID::IdForTab(web_contents), | 98 SessionID::IdForTab(web_contents), |
92 Profile::FromBrowserContext(web_contents->GetBrowserContext()))); | 99 Profile::FromBrowserContext(web_contents->GetBrowserContext()))); |
93 if (FeatureSwitch::script_badges()->IsEnabled()) { | 100 if (FeatureSwitch::script_badges()->IsEnabled()) { |
94 location_bar_controller_.reset( | 101 location_bar_controller_.reset( |
95 new ScriptBadgeController(web_contents, this)); | 102 new ScriptBadgeController(web_contents, this)); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 184 |
178 void TabHelper::RenderViewCreated(RenderViewHost* render_view_host) { | 185 void TabHelper::RenderViewCreated(RenderViewHost* render_view_host) { |
179 render_view_host->Send( | 186 render_view_host->Send( |
180 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), | 187 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), |
181 SessionID::IdForTab(web_contents()))); | 188 SessionID::IdForTab(web_contents()))); |
182 } | 189 } |
183 | 190 |
184 void TabHelper::DidNavigateMainFrame( | 191 void TabHelper::DidNavigateMainFrame( |
185 const content::LoadCommittedDetails& details, | 192 const content::LoadCommittedDetails& details, |
186 const content::FrameNavigateParams& params) { | 193 const content::FrameNavigateParams& params) { |
| 194 content_rules_registry_->DidNavigateMainFrame( |
| 195 web_contents(), details, params); |
| 196 |
187 if (details.is_in_page) | 197 if (details.is_in_page) |
188 return; | 198 return; |
189 | 199 |
190 Profile* profile = | 200 Profile* profile = |
191 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 201 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
192 ExtensionService* service = profile->GetExtensionService(); | 202 ExtensionService* service = profile->GetExtensionService(); |
193 if (!service) | 203 if (!service) |
194 return; | 204 return; |
195 | 205 |
196 ExtensionActionManager* extension_action_manager = | 206 ExtensionActionManager* extension_action_manager = |
(...skipping 21 matching lines...) Expand all Loading... |
218 OnInstallApplication) | 228 OnInstallApplication) |
219 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, | 229 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, |
220 OnInlineWebstoreInstall) | 230 OnInlineWebstoreInstall) |
221 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppNotifyChannel, | 231 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppNotifyChannel, |
222 OnGetAppNotifyChannel) | 232 OnGetAppNotifyChannel) |
223 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, | 233 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, |
224 OnGetAppInstallState); | 234 OnGetAppInstallState); |
225 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | 235 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
226 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, | 236 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, |
227 OnContentScriptsExecuting) | 237 OnContentScriptsExecuting) |
| 238 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OnWatchedPageChange, |
| 239 OnWatchedPageChange) |
228 IPC_MESSAGE_UNHANDLED(handled = false) | 240 IPC_MESSAGE_UNHANDLED(handled = false) |
229 IPC_END_MESSAGE_MAP() | 241 IPC_END_MESSAGE_MAP() |
230 return handled; | 242 return handled; |
231 } | 243 } |
232 | 244 |
233 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, | 245 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, |
234 WebContents* new_web_contents) { | 246 WebContents* new_web_contents) { |
235 // When the WebContents that this is attached to is cloned, give the new clone | 247 // When the WebContents that this is attached to is cloned, give the new clone |
236 // a TabHelper and copy state over. | 248 // a TabHelper and copy state over. |
237 CreateForWebContents(new_web_contents); | 249 CreateForWebContents(new_web_contents); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 const ScriptExecutionObserver::ExecutingScriptsMap& executing_scripts_map, | 418 const ScriptExecutionObserver::ExecutingScriptsMap& executing_scripts_map, |
407 int32 on_page_id, | 419 int32 on_page_id, |
408 const GURL& on_url) { | 420 const GURL& on_url) { |
409 FOR_EACH_OBSERVER(ScriptExecutionObserver, script_execution_observers_, | 421 FOR_EACH_OBSERVER(ScriptExecutionObserver, script_execution_observers_, |
410 OnScriptsExecuted(web_contents(), | 422 OnScriptsExecuted(web_contents(), |
411 executing_scripts_map, | 423 executing_scripts_map, |
412 on_page_id, | 424 on_page_id, |
413 on_url)); | 425 on_url)); |
414 } | 426 } |
415 | 427 |
| 428 void TabHelper::OnWatchedPageChange( |
| 429 const std::vector<std::string>& css_selectors) { |
| 430 content_rules_registry_->Apply(web_contents(), css_selectors); |
| 431 } |
| 432 |
416 const Extension* TabHelper::GetExtension(const std::string& extension_app_id) { | 433 const Extension* TabHelper::GetExtension(const std::string& extension_app_id) { |
417 if (extension_app_id.empty()) | 434 if (extension_app_id.empty()) |
418 return NULL; | 435 return NULL; |
419 | 436 |
420 Profile* profile = | 437 Profile* profile = |
421 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 438 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
422 ExtensionService* extension_service = profile->GetExtensionService(); | 439 ExtensionService* extension_service = profile->GetExtensionService(); |
423 if (!extension_service || !extension_service->is_ready()) | 440 if (!extension_service || !extension_service->is_ready()) |
424 return NULL; | 441 return NULL; |
425 | 442 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 script_bubble_controller_->OnExtensionUnloaded( | 529 script_bubble_controller_->OnExtensionUnloaded( |
513 content::Details<extensions::UnloadedExtensionInfo>( | 530 content::Details<extensions::UnloadedExtensionInfo>( |
514 details)->extension->id()); | 531 details)->extension->id()); |
515 break; | 532 break; |
516 } | 533 } |
517 } | 534 } |
518 } | 535 } |
519 } | 536 } |
520 | 537 |
521 } // namespace extensions | 538 } // namespace extensions |
OLD | NEW |