| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 } | 325 } |
| 326 } else { | 326 } else { |
| 327 UpdateExtensionAppIcon( | 327 UpdateExtensionAppIcon( |
| 328 enabled_extensions.GetExtensionOrAppByURL(navigation_handle->GetURL())); | 328 enabled_extensions.GetExtensionOrAppByURL(navigation_handle->GetURL())); |
| 329 } | 329 } |
| 330 | 330 |
| 331 if (!navigation_handle->IsSameDocument()) | 331 if (!navigation_handle->IsSameDocument()) |
| 332 ExtensionActionAPI::Get(context)->ClearAllValuesForTab(web_contents()); | 332 ExtensionActionAPI::Get(context)->ClearAllValuesForTab(web_contents()); |
| 333 } | 333 } |
| 334 | 334 |
| 335 bool TabHelper::OnMessageReceived(const IPC::Message& message) { | 335 bool TabHelper::OnMessageReceived(const IPC::Message& message, |
| 336 content::RenderFrameHost* sender) { |
| 336 bool handled = true; | 337 bool handled = true; |
| 337 IPC_BEGIN_MESSAGE_MAP(TabHelper, message) | 338 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(TabHelper, message, sender) |
| 338 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidGetWebApplicationInfo, | 339 IPC_MESSAGE_HANDLER(ChromeFrameHostMsg_DidGetWebApplicationInfo, |
| 339 OnDidGetWebApplicationInfo) | 340 OnDidGetWebApplicationInfo) |
| 340 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 341 IPC_END_MESSAGE_MAP() | |
| 342 return handled; | |
| 343 } | |
| 344 | |
| 345 bool TabHelper::OnMessageReceived(const IPC::Message& message, | |
| 346 content::RenderFrameHost* render_frame_host) { | |
| 347 bool handled = true; | |
| 348 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(TabHelper, message, render_frame_host) | |
| 349 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, | 341 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, |
| 350 OnGetAppInstallState) | 342 OnGetAppInstallState) |
| 351 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, | 343 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, |
| 352 OnContentScriptsExecuting) | 344 OnContentScriptsExecuting) |
| 353 IPC_MESSAGE_UNHANDLED(handled = false) | 345 IPC_MESSAGE_UNHANDLED(handled = false) |
| 354 IPC_END_MESSAGE_MAP() | 346 IPC_END_MESSAGE_MAP() |
| 355 return handled; | 347 return handled; |
| 356 } | 348 } |
| 357 | 349 |
| 358 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, | 350 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, |
| 359 WebContents* new_web_contents) { | 351 WebContents* new_web_contents) { |
| 360 // When the WebContents that this is attached to is cloned, give the new clone | 352 // When the WebContents that this is attached to is cloned, give the new clone |
| 361 // a TabHelper and copy state over. | 353 // a TabHelper and copy state over. |
| 362 CreateForWebContents(new_web_contents); | 354 CreateForWebContents(new_web_contents); |
| 363 TabHelper* new_helper = FromWebContents(new_web_contents); | 355 TabHelper* new_helper = FromWebContents(new_web_contents); |
| 364 | 356 |
| 365 new_helper->SetExtensionApp(extension_app()); | 357 new_helper->SetExtensionApp(extension_app()); |
| 366 new_helper->extension_app_icon_ = extension_app_icon_; | 358 new_helper->extension_app_icon_ = extension_app_icon_; |
| 367 } | 359 } |
| 368 | 360 |
| 369 void TabHelper::OnDidGetWebApplicationInfo(const WebApplicationInfo& info) { | 361 void TabHelper::OnDidGetWebApplicationInfo(content::RenderFrameHost* sender, |
| 362 const WebApplicationInfo& info) { |
| 370 web_app_info_ = info; | 363 web_app_info_ = info; |
| 371 | 364 |
| 372 NavigationEntry* entry = | 365 NavigationEntry* entry = |
| 373 web_contents()->GetController().GetLastCommittedEntry(); | 366 web_contents()->GetController().GetLastCommittedEntry(); |
| 374 if (!entry || last_committed_nav_entry_unique_id_ != entry->GetUniqueID()) | 367 if (!entry || last_committed_nav_entry_unique_id_ != entry->GetUniqueID()) |
| 375 return; | 368 return; |
| 376 last_committed_nav_entry_unique_id_ = 0; | 369 last_committed_nav_entry_unique_id_ = 0; |
| 377 | 370 |
| 378 switch (pending_web_app_action_) { | 371 switch (pending_web_app_action_) { |
| 379 case CREATE_HOSTED_APP: { | 372 case CREATE_HOSTED_APP: { |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 | 610 |
| 618 void TabHelper::GetApplicationInfo(WebAppAction action) { | 611 void TabHelper::GetApplicationInfo(WebAppAction action) { |
| 619 NavigationEntry* entry = | 612 NavigationEntry* entry = |
| 620 web_contents()->GetController().GetLastCommittedEntry(); | 613 web_contents()->GetController().GetLastCommittedEntry(); |
| 621 if (!entry) | 614 if (!entry) |
| 622 return; | 615 return; |
| 623 | 616 |
| 624 pending_web_app_action_ = action; | 617 pending_web_app_action_ = action; |
| 625 last_committed_nav_entry_unique_id_ = entry->GetUniqueID(); | 618 last_committed_nav_entry_unique_id_ = entry->GetUniqueID(); |
| 626 | 619 |
| 627 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id())); | 620 content::RenderFrameHost* main_frame = web_contents()->GetMainFrame(); |
| 621 main_frame->Send( |
| 622 new ChromeFrameMsg_GetWebApplicationInfo(main_frame->GetRoutingID())); |
| 628 } | 623 } |
| 629 | 624 |
| 630 void TabHelper::Observe(int type, | 625 void TabHelper::Observe(int type, |
| 631 const content::NotificationSource& source, | 626 const content::NotificationSource& source, |
| 632 const content::NotificationDetails& details) { | 627 const content::NotificationDetails& details) { |
| 633 DCHECK_EQ(content::NOTIFICATION_LOAD_STOP, type); | 628 DCHECK_EQ(content::NOTIFICATION_LOAD_STOP, type); |
| 634 const NavigationController& controller = | 629 const NavigationController& controller = |
| 635 *content::Source<NavigationController>(source).ptr(); | 630 *content::Source<NavigationController>(source).ptr(); |
| 636 DCHECK_EQ(controller.GetWebContents(), web_contents()); | 631 DCHECK_EQ(controller.GetWebContents(), web_contents()); |
| 637 | 632 |
| 638 if (update_shortcut_on_load_complete_) { | 633 if (update_shortcut_on_load_complete_) { |
| 639 update_shortcut_on_load_complete_ = false; | 634 update_shortcut_on_load_complete_ = false; |
| 640 // Schedule a shortcut update when web application info is available if | 635 // Schedule a shortcut update when web application info is available if |
| 641 // last committed entry is not NULL. Last committed entry could be NULL | 636 // last committed entry is not NULL. Last committed entry could be NULL |
| 642 // when an interstitial page is injected (e.g. bad https certificate, | 637 // when an interstitial page is injected (e.g. bad https certificate, |
| 643 // malware site etc). When this happens, we abort the shortcut update. | 638 // malware site etc). When this happens, we abort the shortcut update. |
| 644 if (controller.GetLastCommittedEntry()) | 639 if (controller.GetLastCommittedEntry()) |
| 645 GetApplicationInfo(UPDATE_SHORTCUT); | 640 GetApplicationInfo(UPDATE_SHORTCUT); |
| 646 } | 641 } |
| 647 } | 642 } |
| 648 | 643 |
| 649 void TabHelper::SetTabId(content::RenderFrameHost* render_frame_host) { | 644 void TabHelper::SetTabId(content::RenderFrameHost* render_frame_host) { |
| 650 render_frame_host->Send( | 645 render_frame_host->Send( |
| 651 new ExtensionMsg_SetTabId(render_frame_host->GetRoutingID(), | 646 new ExtensionMsg_SetTabId(render_frame_host->GetRoutingID(), |
| 652 SessionTabHelper::IdForTab(web_contents()))); | 647 SessionTabHelper::IdForTab(web_contents()))); |
| 653 } | 648 } |
| 654 | 649 |
| 655 } // namespace extensions | 650 } // namespace extensions |
| OLD | NEW |