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

Side by Side Diff: chrome/browser/extensions/api/extension_action/extension_page_actions_api.cc

Issue 11312228: Move extension_error_utils.* and url_pattern_set.* into (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: hate Created 8 years, 1 month 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/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/common/extensions/extension.h" 19 #include "chrome/common/extensions/extension.h"
20 #include "chrome/common/extensions/extension_error_utils.h"
21 #include "content/public/browser/navigation_entry.h" 20 #include "content/public/browser/navigation_entry.h"
22 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
22 #include "extensions/common/error_utils.h"
23 23
24 using content::NavigationEntry; 24 using content::NavigationEntry;
25 using extensions::ErrorUtils;
25 26
26 namespace keys = extension_page_actions_api_constants; 27 namespace keys = extension_page_actions_api_constants;
27 28
28 namespace { 29 namespace {
29 // Errors. 30 // Errors.
30 const char kNoTabError[] = "No tab with id: *."; 31 const char kNoTabError[] = "No tab with id: *.";
31 const char kNoPageActionError[] = 32 const char kNoPageActionError[] =
32 "This extension has no page action specified."; 33 "This extension has no page action specified.";
33 const char kUrlNotActiveError[] = "This url is no longer active: *."; 34 const char kUrlNotActiveError[] = "This url is no longer active: *.";
34 } 35 }
(...skipping 27 matching lines...) Expand all
62 if (!page_action) { 63 if (!page_action) {
63 error_ = kNoPageActionError; 64 error_ = kNoPageActionError;
64 return false; 65 return false;
65 } 66 }
66 67
67 // Find the WebContents that contains this tab id. 68 // Find the WebContents that contains this tab id.
68 content::WebContents* contents = NULL; 69 content::WebContents* contents = NULL;
69 bool result = ExtensionTabUtil::GetTabById( 70 bool result = ExtensionTabUtil::GetTabById(
70 tab_id, profile(), include_incognito(), NULL, NULL, &contents, NULL); 71 tab_id, profile(), include_incognito(), NULL, NULL, &contents, NULL);
71 if (!result || !contents) { 72 if (!result || !contents) {
72 error_ = ExtensionErrorUtils::FormatErrorMessage( 73 error_ = ErrorUtils::FormatErrorMessage(
73 kNoTabError, base::IntToString(tab_id)); 74 kNoTabError, base::IntToString(tab_id));
74 return false; 75 return false;
75 } 76 }
76 77
77 // Make sure the URL hasn't changed. 78 // Make sure the URL hasn't changed.
78 NavigationEntry* entry = contents->GetController().GetActiveEntry(); 79 NavigationEntry* entry = contents->GetController().GetActiveEntry();
79 if (!entry || url != entry->GetURL().spec()) { 80 if (!entry || url != entry->GetURL().spec()) {
80 error_ = ExtensionErrorUtils::FormatErrorMessage(kUrlNotActiveError, url); 81 error_ = ErrorUtils::FormatErrorMessage(kUrlNotActiveError, url);
81 return false; 82 return false;
82 } 83 }
83 84
84 // Set visibility and broadcast notifications that the UI should be updated. 85 // Set visibility and broadcast notifications that the UI should be updated.
85 page_action->SetAppearance( 86 page_action->SetAppearance(
86 tab_id, enable ? ExtensionAction::ACTIVE : ExtensionAction::INVISIBLE); 87 tab_id, enable ? ExtensionAction::ACTIVE : ExtensionAction::INVISIBLE);
87 page_action->SetTitle(tab_id, title); 88 page_action->SetTitle(tab_id, title);
88 extensions::TabHelper::FromWebContents(contents)-> 89 extensions::TabHelper::FromWebContents(contents)->
89 location_bar_controller()->NotifyChange(); 90 location_bar_controller()->NotifyChange();
90 91
91 return true; 92 return true;
92 } 93 }
93 94
94 bool EnablePageActionsFunction::RunImpl() { 95 bool EnablePageActionsFunction::RunImpl() {
95 return SetPageActionEnabled(true); 96 return SetPageActionEnabled(true);
96 } 97 }
97 98
98 bool DisablePageActionsFunction::RunImpl() { 99 bool DisablePageActionsFunction::RunImpl() {
99 return SetPageActionEnabled(false); 100 return SetPageActionEnabled(false);
100 } 101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698