Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1269)

Side by Side Diff: chrome/browser/extensions/tab_helper.cc

Issue 349713002: Android: Remove events extensions API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 SetTabId(web_contents->GetRenderViewHost()); 115 SetTabId(web_contents->GetRenderViewHost());
116 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter( 116 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter(
117 web_contents, 117 web_contents,
118 SessionID::IdForTab(web_contents), 118 SessionID::IdForTab(web_contents),
119 Profile::FromBrowserContext(web_contents->GetBrowserContext()))); 119 Profile::FromBrowserContext(web_contents->GetBrowserContext())));
120 120
121 // If more classes need to listen to global content script activity, then 121 // If more classes need to listen to global content script activity, then
122 // a separate routing class with an observer interface should be written. 122 // a separate routing class with an observer interface should be written.
123 profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()); 123 profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext());
124 124
125 #if defined(ENABLE_EXTENSIONS)
126 AddScriptExecutionObserver(ActivityLog::GetInstance(profile_)); 125 AddScriptExecutionObserver(ActivityLog::GetInstance(profile_));
127 #endif
128 126
129 registrar_.Add(this, 127 registrar_.Add(this,
130 content::NOTIFICATION_LOAD_STOP, 128 content::NOTIFICATION_LOAD_STOP,
131 content::Source<NavigationController>( 129 content::Source<NavigationController>(
132 &web_contents->GetController())); 130 &web_contents->GetController()));
133 } 131 }
134 132
135 TabHelper::~TabHelper() { 133 TabHelper::~TabHelper() {
136 #if defined(ENABLE_EXTENSIONS)
137 RemoveScriptExecutionObserver(ActivityLog::GetInstance(profile_)); 134 RemoveScriptExecutionObserver(ActivityLog::GetInstance(profile_));
138 #endif
139 } 135 }
140 136
141 void TabHelper::CreateApplicationShortcuts() { 137 void TabHelper::CreateApplicationShortcuts() {
142 DCHECK(CanCreateApplicationShortcuts()); 138 DCHECK(CanCreateApplicationShortcuts());
143 NavigationEntry* entry = 139 NavigationEntry* entry =
144 web_contents()->GetController().GetLastCommittedEntry(); 140 web_contents()->GetController().GetLastCommittedEntry();
145 if (!entry) 141 if (!entry)
146 return; 142 return;
147 143
148 pending_web_app_action_ = CREATE_SHORTCUT; 144 pending_web_app_action_ = CREATE_SHORTCUT;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 pending_web_app_action_ = NONE; 220 pending_web_app_action_ = NONE;
225 221
226 // There was an error with downloading the icons or installing the app. 222 // There was an error with downloading the icons or installing the app.
227 if (!extension) 223 if (!extension)
228 return; 224 return;
229 225
230 #if defined(OS_CHROMEOS) 226 #if defined(OS_CHROMEOS)
231 ChromeLauncherController::instance()->PinAppWithID(extension->id()); 227 ChromeLauncherController::instance()->PinAppWithID(extension->id());
232 #endif 228 #endif
233 229
234 // Android does not implement browser_finder.cc.
235 #if !defined(OS_ANDROID)
236 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); 230 Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
237 if (browser) { 231 if (browser) {
238 browser->window()->ShowBookmarkAppBubble(web_app_info, extension->id()); 232 browser->window()->ShowBookmarkAppBubble(web_app_info, extension->id());
239 } 233 }
240 #endif
241 } 234 }
242 235
243 void TabHelper::RenderViewCreated(RenderViewHost* render_view_host) { 236 void TabHelper::RenderViewCreated(RenderViewHost* render_view_host) {
244 SetTabId(render_view_host); 237 SetTabId(render_view_host);
245 } 238 }
246 239
247 void TabHelper::DidNavigateMainFrame( 240 void TabHelper::DidNavigateMainFrame(
248 const content::LoadCommittedDetails& details, 241 const content::LoadCommittedDetails& details,
249 const content::FrameNavigateParams& params) { 242 const content::FrameNavigateParams& params) {
250 #if defined(ENABLE_EXTENSIONS)
251 if (ExtensionSystem::Get(profile_)->extension_service() && 243 if (ExtensionSystem::Get(profile_)->extension_service() &&
252 RulesRegistryService::Get(profile_)) { 244 RulesRegistryService::Get(profile_)) {
253 RulesRegistryService::Get(profile_)->content_rules_registry()-> 245 RulesRegistryService::Get(profile_)->content_rules_registry()->
254 DidNavigateMainFrame(web_contents(), details, params); 246 DidNavigateMainFrame(web_contents(), details, params);
255 } 247 }
256 #endif // defined(ENABLE_EXTENSIONS)
257 248
258 content::BrowserContext* context = web_contents()->GetBrowserContext(); 249 content::BrowserContext* context = web_contents()->GetBrowserContext();
259 ExtensionRegistry* registry = ExtensionRegistry::Get(context); 250 ExtensionRegistry* registry = ExtensionRegistry::Get(context);
260 const ExtensionSet& enabled_extensions = registry->enabled_extensions(); 251 const ExtensionSet& enabled_extensions = registry->enabled_extensions();
261 252
262 if (CommandLine::ForCurrentProcess()->HasSwitch( 253 if (CommandLine::ForCurrentProcess()->HasSwitch(
263 switches::kEnableStreamlinedHostedApps)) { 254 switches::kEnableStreamlinedHostedApps)) {
264 #if !defined(OS_ANDROID)
265 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); 255 Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
266 if (browser && browser->is_app()) { 256 if (browser && browser->is_app()) {
267 SetExtensionApp(registry->GetExtensionById( 257 SetExtensionApp(registry->GetExtensionById(
268 web_app::GetExtensionIdFromApplicationName(browser->app_name()), 258 web_app::GetExtensionIdFromApplicationName(browser->app_name()),
269 ExtensionRegistry::EVERYTHING)); 259 ExtensionRegistry::EVERYTHING));
270 } else { 260 } else {
271 UpdateExtensionAppIcon( 261 UpdateExtensionAppIcon(
272 enabled_extensions.GetExtensionOrAppByURL(params.url)); 262 enabled_extensions.GetExtensionOrAppByURL(params.url));
273 } 263 }
274 #endif
275 } else { 264 } else {
276 UpdateExtensionAppIcon( 265 UpdateExtensionAppIcon(
277 enabled_extensions.GetExtensionOrAppByURL(params.url)); 266 enabled_extensions.GetExtensionOrAppByURL(params.url));
278 } 267 }
279 268
280 if (details.is_in_page) 269 if (details.is_in_page)
281 return; 270 return;
282 271
283 ExtensionActionManager* extension_action_manager = 272 ExtensionActionManager* extension_action_manager =
284 ExtensionActionManager::Get(Profile::FromBrowserContext(context)); 273 ExtensionActionManager::Get(Profile::FromBrowserContext(context));
(...skipping 26 matching lines...) Expand all
311 OnContentScriptsExecuting) 300 OnContentScriptsExecuting)
312 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OnWatchedPageChange, 301 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OnWatchedPageChange,
313 OnWatchedPageChange) 302 OnWatchedPageChange)
314 IPC_MESSAGE_UNHANDLED(handled = false) 303 IPC_MESSAGE_UNHANDLED(handled = false)
315 IPC_END_MESSAGE_MAP() 304 IPC_END_MESSAGE_MAP()
316 return handled; 305 return handled;
317 } 306 }
318 307
319 bool TabHelper::OnMessageReceived(const IPC::Message& message, 308 bool TabHelper::OnMessageReceived(const IPC::Message& message,
320 content::RenderFrameHost* render_frame_host) { 309 content::RenderFrameHost* render_frame_host) {
321 #if defined(ENABLE_EXTENSIONS)
322 bool handled = true; 310 bool handled = true;
323 IPC_BEGIN_MESSAGE_MAP(TabHelper, message) 311 IPC_BEGIN_MESSAGE_MAP(TabHelper, message)
324 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DetailedConsoleMessageAdded, 312 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DetailedConsoleMessageAdded,
325 OnDetailedConsoleMessageAdded) 313 OnDetailedConsoleMessageAdded)
326 IPC_MESSAGE_UNHANDLED(handled = false) 314 IPC_MESSAGE_UNHANDLED(handled = false)
327 IPC_END_MESSAGE_MAP() 315 IPC_END_MESSAGE_MAP()
328 #else
329 bool handled = false;
330 #endif
331 return handled; 316 return handled;
332 } 317 }
333 318
334 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, 319 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents,
335 WebContents* new_web_contents) { 320 WebContents* new_web_contents) {
336 // When the WebContents that this is attached to is cloned, give the new clone 321 // When the WebContents that this is attached to is cloned, give the new clone
337 // a TabHelper and copy state over. 322 // a TabHelper and copy state over.
338 CreateForWebContents(new_web_contents); 323 CreateForWebContents(new_web_contents);
339 TabHelper* new_helper = FromWebContents(new_web_contents); 324 TabHelper* new_helper = FromWebContents(new_web_contents);
340 325
341 new_helper->SetExtensionApp(extension_app()); 326 new_helper->SetExtensionApp(extension_app());
342 new_helper->extension_app_icon_ = extension_app_icon_; 327 new_helper->extension_app_icon_ = extension_app_icon_;
343 } 328 }
344 329
345 void TabHelper::OnDidGetApplicationInfo(int32 page_id, 330 void TabHelper::OnDidGetApplicationInfo(int32 page_id,
346 const WebApplicationInfo& info) { 331 const WebApplicationInfo& info) {
347 // Android does not implement BrowserWindow. 332 #if !defined(OS_MACOSX)
348 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
349 web_app_info_ = info; 333 web_app_info_ = info;
350 334
351 NavigationEntry* entry = 335 NavigationEntry* entry =
352 web_contents()->GetController().GetLastCommittedEntry(); 336 web_contents()->GetController().GetLastCommittedEntry();
353 if (!entry || (entry->GetPageID() != page_id)) 337 if (!entry || (entry->GetPageID() != page_id))
354 return; 338 return;
355 339
356 switch (pending_web_app_action_) { 340 switch (pending_web_app_action_) {
357 case CREATE_SHORTCUT: { 341 case CREATE_SHORTCUT: {
358 chrome::ShowCreateWebAppShortcutsDialog( 342 chrome::ShowCreateWebAppShortcutsDialog(
(...skipping 30 matching lines...) Expand all
389 if (pending_web_app_action_ != CREATE_HOSTED_APP) 373 if (pending_web_app_action_ != CREATE_HOSTED_APP)
390 pending_web_app_action_ = NONE; 374 pending_web_app_action_ = NONE;
391 #endif 375 #endif
392 } 376 }
393 377
394 void TabHelper::OnInlineWebstoreInstall(int install_id, 378 void TabHelper::OnInlineWebstoreInstall(int install_id,
395 int return_route_id, 379 int return_route_id,
396 const std::string& webstore_item_id, 380 const std::string& webstore_item_id,
397 const GURL& requestor_url, 381 const GURL& requestor_url,
398 int listeners_mask) { 382 int listeners_mask) {
399 #if defined(ENABLE_EXTENSIONS)
400 // Check that the listener is reasonable. We should never get anything other 383 // Check that the listener is reasonable. We should never get anything other
401 // than an install stage listener, a download listener, or both. 384 // than an install stage listener, a download listener, or both.
402 if ((listeners_mask & ~(api::webstore::INSTALL_STAGE_LISTENER | 385 if ((listeners_mask & ~(api::webstore::INSTALL_STAGE_LISTENER |
403 api::webstore::DOWNLOAD_PROGRESS_LISTENER)) != 0) { 386 api::webstore::DOWNLOAD_PROGRESS_LISTENER)) != 0) {
404 NOTREACHED(); 387 NOTREACHED();
405 return; 388 return;
406 } 389 }
407 // Inform the Webstore API that an inline install is happening, in case the 390 // Inform the Webstore API that an inline install is happening, in case the
408 // page requested status updates. 391 // page requested status updates.
409 Profile* profile = 392 Profile* profile =
410 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 393 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
411 WebstoreAPI::Get(profile)->OnInlineInstallStart( 394 WebstoreAPI::Get(profile)->OnInlineInstallStart(
412 return_route_id, this, webstore_item_id, listeners_mask); 395 return_route_id, this, webstore_item_id, listeners_mask);
413 #endif
414 396
415 WebstoreStandaloneInstaller::Callback callback = 397 WebstoreStandaloneInstaller::Callback callback =
416 base::Bind(&TabHelper::OnInlineInstallComplete, base::Unretained(this), 398 base::Bind(&TabHelper::OnInlineInstallComplete, base::Unretained(this),
417 install_id, return_route_id); 399 install_id, return_route_id);
418 scoped_refptr<WebstoreInlineInstaller> installer( 400 scoped_refptr<WebstoreInlineInstaller> installer(
419 webstore_inline_installer_factory_->CreateInstaller( 401 webstore_inline_installer_factory_->CreateInstaller(
420 web_contents(), 402 web_contents(),
421 webstore_item_id, 403 webstore_item_id,
422 requestor_url, 404 requestor_url,
423 callback)); 405 callback));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 const GURL& on_url) { 437 const GURL& on_url) {
456 FOR_EACH_OBSERVER(ScriptExecutionObserver, script_execution_observers_, 438 FOR_EACH_OBSERVER(ScriptExecutionObserver, script_execution_observers_,
457 OnScriptsExecuted(web_contents(), 439 OnScriptsExecuted(web_contents(),
458 executing_scripts_map, 440 executing_scripts_map,
459 on_page_id, 441 on_page_id,
460 on_url)); 442 on_url));
461 } 443 }
462 444
463 void TabHelper::OnWatchedPageChange( 445 void TabHelper::OnWatchedPageChange(
464 const std::vector<std::string>& css_selectors) { 446 const std::vector<std::string>& css_selectors) {
465 #if defined(ENABLE_EXTENSIONS)
466 if (ExtensionSystem::Get(profile_)->extension_service() && 447 if (ExtensionSystem::Get(profile_)->extension_service() &&
467 RulesRegistryService::Get(profile_)) { 448 RulesRegistryService::Get(profile_)) {
468 RulesRegistryService::Get(profile_)->content_rules_registry()->Apply( 449 RulesRegistryService::Get(profile_)->content_rules_registry()->Apply(
469 web_contents(), css_selectors); 450 web_contents(), css_selectors);
470 } 451 }
471 #endif // defined(ENABLE_EXTENSIONS)
472 } 452 }
473 453
474 void TabHelper::OnDetailedConsoleMessageAdded( 454 void TabHelper::OnDetailedConsoleMessageAdded(
475 const base::string16& message, 455 const base::string16& message,
476 const base::string16& source, 456 const base::string16& source,
477 const StackTrace& stack_trace, 457 const StackTrace& stack_trace,
478 int32 severity_level) { 458 int32 severity_level) {
479 #if defined(ENABLE_EXTENSIONS)
480 if (IsSourceFromAnExtension(source)) { 459 if (IsSourceFromAnExtension(source)) {
481 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); 460 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost();
482 ErrorConsole::Get(profile_)->ReportError( 461 ErrorConsole::Get(profile_)->ReportError(
483 scoped_ptr<ExtensionError>(new RuntimeError( 462 scoped_ptr<ExtensionError>(new RuntimeError(
484 extension_app_ ? extension_app_->id() : std::string(), 463 extension_app_ ? extension_app_->id() : std::string(),
485 profile_->IsOffTheRecord(), 464 profile_->IsOffTheRecord(),
486 source, 465 source,
487 message, 466 message,
488 stack_trace, 467 stack_trace,
489 web_contents() ? 468 web_contents() ?
490 web_contents()->GetLastCommittedURL() : GURL::EmptyGURL(), 469 web_contents()->GetLastCommittedURL() : GURL::EmptyGURL(),
491 static_cast<logging::LogSeverity>(severity_level), 470 static_cast<logging::LogSeverity>(severity_level),
492 rvh->GetRoutingID(), 471 rvh->GetRoutingID(),
493 rvh->GetProcess()->GetID()))); 472 rvh->GetProcess()->GetID())));
494 } 473 }
495 #endif
496 } 474 }
497 475
498 const Extension* TabHelper::GetExtension(const std::string& extension_app_id) { 476 const Extension* TabHelper::GetExtension(const std::string& extension_app_id) {
499 if (extension_app_id.empty()) 477 if (extension_app_id.empty())
500 return NULL; 478 return NULL;
501 479
502 Profile* profile = 480 Profile* profile =
503 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 481 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
504 ExtensionService* extension_service = profile->GetExtensionService(); 482 ExtensionService* extension_service = profile->GetExtensionService();
505 if (!extension_service || !extension_service->is_ready()) 483 if (!extension_service || !extension_service->is_ready())
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 } 572 }
595 } 573 }
596 574
597 void TabHelper::SetTabId(RenderViewHost* render_view_host) { 575 void TabHelper::SetTabId(RenderViewHost* render_view_host) {
598 render_view_host->Send( 576 render_view_host->Send(
599 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), 577 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(),
600 SessionID::IdForTab(web_contents()))); 578 SessionID::IdForTab(web_contents())));
601 } 579 }
602 580
603 } // namespace extensions 581 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/activity_log/activity_log.cc ('k') | chrome/browser/sessions/tab_restore_service_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698