| 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/api/extension_action/extension_page_actions_
api.h" | 5 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_
api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_
api_constants.h" | 10 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_
api_constants.h" |
| 11 #include "chrome/browser/extensions/extension_action.h" | 11 #include "chrome/browser/extensions/extension_action.h" |
| 12 #include "chrome/browser/extensions/extension_action_manager.h" | 12 #include "chrome/browser/extensions/extension_action_manager.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/extensions/extension_tab_util.h" | 14 #include "chrome/browser/extensions/extension_tab_util.h" |
| 15 #include "chrome/browser/extensions/location_bar_controller.h" | 15 #include "chrome/browser/extensions/location_bar_controller.h" |
| 16 #include "chrome/browser/extensions/tab_helper.h" | 16 #include "chrome/browser/extensions/tab_helper.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
| 19 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
| 20 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
| 21 #include "chrome/common/extensions/extension_error_utils.h" | 20 #include "chrome/common/extensions/extension_error_utils.h" |
| 22 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" |
| 23 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 24 | 23 |
| 25 using content::NavigationEntry; | 24 using content::NavigationEntry; |
| 26 | 25 |
| 27 namespace keys = extension_page_actions_api_constants; | 26 namespace keys = extension_page_actions_api_constants; |
| 28 | 27 |
| 29 namespace { | 28 namespace { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 58 } | 57 } |
| 59 | 58 |
| 60 ExtensionAction* page_action = | 59 ExtensionAction* page_action = |
| 61 extensions::ExtensionActionManager::Get(profile())-> | 60 extensions::ExtensionActionManager::Get(profile())-> |
| 62 GetPageAction(*GetExtension()); | 61 GetPageAction(*GetExtension()); |
| 63 if (!page_action) { | 62 if (!page_action) { |
| 64 error_ = kNoPageActionError; | 63 error_ = kNoPageActionError; |
| 65 return false; | 64 return false; |
| 66 } | 65 } |
| 67 | 66 |
| 68 // Find the TabContents that contains this tab id. | 67 // Find the WebContents that contains this tab id. |
| 69 TabContents* contents = NULL; | 68 content::WebContents* contents = NULL; |
| 70 bool result = ExtensionTabUtil::GetTabById( | 69 bool result = ExtensionTabUtil::GetTabById( |
| 71 tab_id, profile(), include_incognito(), NULL, NULL, &contents, NULL); | 70 tab_id, profile(), include_incognito(), NULL, NULL, &contents, NULL); |
| 72 if (!result || !contents) { | 71 if (!result || !contents) { |
| 73 error_ = ExtensionErrorUtils::FormatErrorMessage( | 72 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 74 kNoTabError, base::IntToString(tab_id)); | 73 kNoTabError, base::IntToString(tab_id)); |
| 75 return false; | 74 return false; |
| 76 } | 75 } |
| 77 | 76 |
| 78 // Make sure the URL hasn't changed. | 77 // Make sure the URL hasn't changed. |
| 79 NavigationEntry* entry = | 78 NavigationEntry* entry = contents->GetController().GetActiveEntry(); |
| 80 contents->web_contents()->GetController().GetActiveEntry(); | |
| 81 if (!entry || url != entry->GetURL().spec()) { | 79 if (!entry || url != entry->GetURL().spec()) { |
| 82 error_ = ExtensionErrorUtils::FormatErrorMessage(kUrlNotActiveError, url); | 80 error_ = ExtensionErrorUtils::FormatErrorMessage(kUrlNotActiveError, url); |
| 83 return false; | 81 return false; |
| 84 } | 82 } |
| 85 | 83 |
| 86 // Set visibility and broadcast notifications that the UI should be updated. | 84 // Set visibility and broadcast notifications that the UI should be updated. |
| 87 page_action->SetAppearance( | 85 page_action->SetAppearance( |
| 88 tab_id, enable ? ExtensionAction::ACTIVE : ExtensionAction::INVISIBLE); | 86 tab_id, enable ? ExtensionAction::ACTIVE : ExtensionAction::INVISIBLE); |
| 89 page_action->SetTitle(tab_id, title); | 87 page_action->SetTitle(tab_id, title); |
| 90 extensions::TabHelper::FromWebContents(contents->web_contents())-> | 88 extensions::TabHelper::FromWebContents(contents)-> |
| 91 location_bar_controller()->NotifyChange(); | 89 location_bar_controller()->NotifyChange(); |
| 92 | 90 |
| 93 return true; | 91 return true; |
| 94 } | 92 } |
| 95 | 93 |
| 96 bool EnablePageActionsFunction::RunImpl() { | 94 bool EnablePageActionsFunction::RunImpl() { |
| 97 return SetPageActionEnabled(true); | 95 return SetPageActionEnabled(true); |
| 98 } | 96 } |
| 99 | 97 |
| 100 bool DisablePageActionsFunction::RunImpl() { | 98 bool DisablePageActionsFunction::RunImpl() { |
| 101 return SetPageActionEnabled(false); | 99 return SetPageActionEnabled(false); |
| 102 } | 100 } |
| OLD | NEW |