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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 186 |
180 void TabHelper::RenderViewCreated(RenderViewHost* render_view_host) { | 187 void TabHelper::RenderViewCreated(RenderViewHost* render_view_host) { |
181 render_view_host->Send( | 188 render_view_host->Send( |
182 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), | 189 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), |
183 SessionID::IdForTab(web_contents()))); | 190 SessionID::IdForTab(web_contents()))); |
184 } | 191 } |
185 | 192 |
186 void TabHelper::DidNavigateMainFrame( | 193 void TabHelper::DidNavigateMainFrame( |
187 const content::LoadCommittedDetails& details, | 194 const content::LoadCommittedDetails& details, |
188 const content::FrameNavigateParams& params) { | 195 const content::FrameNavigateParams& params) { |
| 196 content_rules_registry_->DidNavigateMainFrame( |
| 197 web_contents(), details, params); |
| 198 |
189 if (details.is_in_page) | 199 if (details.is_in_page) |
190 return; | 200 return; |
191 | 201 |
192 Profile* profile = | 202 Profile* profile = |
193 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 203 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
194 ExtensionService* service = profile->GetExtensionService(); | 204 ExtensionService* service = profile->GetExtensionService(); |
195 if (!service) | 205 if (!service) |
196 return; | 206 return; |
197 | 207 |
198 ExtensionActionManager* extension_action_manager = | 208 ExtensionActionManager* extension_action_manager = |
(...skipping 21 matching lines...) Expand all Loading... |
220 OnInstallApplication) | 230 OnInstallApplication) |
221 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, | 231 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, |
222 OnInlineWebstoreInstall) | 232 OnInlineWebstoreInstall) |
223 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppNotifyChannel, | 233 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppNotifyChannel, |
224 OnGetAppNotifyChannel) | 234 OnGetAppNotifyChannel) |
225 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, | 235 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, |
226 OnGetAppInstallState); | 236 OnGetAppInstallState); |
227 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | 237 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
228 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, | 238 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, |
229 OnContentScriptsExecuting) | 239 OnContentScriptsExecuting) |
| 240 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OnWatchedPageChange, |
| 241 OnWatchedPageChange) |
230 IPC_MESSAGE_UNHANDLED(handled = false) | 242 IPC_MESSAGE_UNHANDLED(handled = false) |
231 IPC_END_MESSAGE_MAP() | 243 IPC_END_MESSAGE_MAP() |
232 return handled; | 244 return handled; |
233 } | 245 } |
234 | 246 |
235 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, | 247 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, |
236 WebContents* new_web_contents) { | 248 WebContents* new_web_contents) { |
237 // When the WebContents that this is attached to is cloned, give the new clone | 249 // When the WebContents that this is attached to is cloned, give the new clone |
238 // a TabHelper and copy state over. | 250 // a TabHelper and copy state over. |
239 CreateForWebContents(new_web_contents); | 251 CreateForWebContents(new_web_contents); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 const ScriptExecutionObserver::ExecutingScriptsMap& executing_scripts_map, | 420 const ScriptExecutionObserver::ExecutingScriptsMap& executing_scripts_map, |
409 int32 on_page_id, | 421 int32 on_page_id, |
410 const GURL& on_url) { | 422 const GURL& on_url) { |
411 FOR_EACH_OBSERVER(ScriptExecutionObserver, script_execution_observers_, | 423 FOR_EACH_OBSERVER(ScriptExecutionObserver, script_execution_observers_, |
412 OnScriptsExecuted(web_contents(), | 424 OnScriptsExecuted(web_contents(), |
413 executing_scripts_map, | 425 executing_scripts_map, |
414 on_page_id, | 426 on_page_id, |
415 on_url)); | 427 on_url)); |
416 } | 428 } |
417 | 429 |
| 430 void TabHelper::OnWatchedPageChange( |
| 431 const std::vector<std::string>& css_selectors) { |
| 432 content_rules_registry_->Apply(web_contents(), css_selectors); |
| 433 } |
| 434 |
418 const Extension* TabHelper::GetExtension(const std::string& extension_app_id) { | 435 const Extension* TabHelper::GetExtension(const std::string& extension_app_id) { |
419 if (extension_app_id.empty()) | 436 if (extension_app_id.empty()) |
420 return NULL; | 437 return NULL; |
421 | 438 |
422 Profile* profile = | 439 Profile* profile = |
423 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 440 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
424 ExtensionService* extension_service = profile->GetExtensionService(); | 441 ExtensionService* extension_service = profile->GetExtensionService(); |
425 if (!extension_service || !extension_service->is_ready()) | 442 if (!extension_service || !extension_service->is_ready()) |
426 return NULL; | 443 return NULL; |
427 | 444 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 script_bubble_controller_->OnExtensionUnloaded( | 531 script_bubble_controller_->OnExtensionUnloaded( |
515 content::Details<extensions::UnloadedExtensionInfo>( | 532 content::Details<extensions::UnloadedExtensionInfo>( |
516 details)->extension->id()); | 533 details)->extension->id()); |
517 break; | 534 break; |
518 } | 535 } |
519 } | 536 } |
520 } | 537 } |
521 } | 538 } |
522 | 539 |
523 } // namespace extensions | 540 } // namespace extensions |
OLD | NEW |