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

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

Issue 4694008: Make pink's TabContentsWrapper change compile on Windows.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/extension_page_actions_module.h" 5 #include "chrome/browser/extensions/extension_page_actions_module.h"
6 6
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "chrome/browser/browser_list.h" 8 #include "chrome/browser/browser_list.h"
9 #include "chrome/browser/extensions/extension_page_actions_module_constants.h" 9 #include "chrome/browser/extensions/extension_page_actions_module_constants.h"
10 #include "chrome/browser/extensions/extension_tabs_module.h" 10 #include "chrome/browser/extensions/extension_tabs_module.h"
11 #include "chrome/browser/extensions/extensions_service.h" 11 #include "chrome/browser/extensions/extensions_service.h"
12 #include "chrome/browser/profile.h" 12 #include "chrome/browser/profile.h"
13 #include "chrome/browser/tab_contents/navigation_entry.h" 13 #include "chrome/browser/tab_contents/navigation_entry.h"
14 #include "chrome/browser/tab_contents/tab_contents.h" 14 #include "chrome/browser/tab_contents/tab_contents.h"
15 #include "chrome/browser/tab_contents_wrapper.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
16 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
17 #include "chrome/common/extensions/extension_action.h" 18 #include "chrome/common/extensions/extension_action.h"
18 #include "chrome/common/extensions/extension_error_utils.h" 19 #include "chrome/common/extensions/extension_error_utils.h"
19 #include "chrome/common/render_messages.h" 20 #include "chrome/common/render_messages.h"
20 21
21 namespace keys = extension_page_actions_module_constants; 22 namespace keys = extension_page_actions_module_constants;
22 23
23 namespace { 24 namespace {
24 // Errors. 25 // Errors.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 return false; 61 return false;
61 } 62 }
62 63
63 if (icon_id < 0 || 64 if (icon_id < 0 ||
64 static_cast<size_t>(icon_id) >= page_action->icon_paths()->size()) { 65 static_cast<size_t>(icon_id) >= page_action->icon_paths()->size()) {
65 error_ = (icon_id == 0) ? kNoIconSpecified : kIconIndexOutOfBounds; 66 error_ = (icon_id == 0) ? kNoIconSpecified : kIconIndexOutOfBounds;
66 return false; 67 return false;
67 } 68 }
68 69
69 // Find the TabContents that contains this tab id. 70 // Find the TabContents that contains this tab id.
70 TabContents* contents = NULL; 71 TabContentsWrapper* contents = NULL;
71 bool result = ExtensionTabUtil::GetTabById( 72 bool result = ExtensionTabUtil::GetTabById(
72 tab_id, profile(), include_incognito(), NULL, NULL, &contents, NULL); 73 tab_id, profile(), include_incognito(), NULL, NULL, &contents, NULL);
73 if (!result || !contents) { 74 if (!result || !contents) {
74 error_ = ExtensionErrorUtils::FormatErrorMessage( 75 error_ = ExtensionErrorUtils::FormatErrorMessage(
75 kNoTabError, base::IntToString(tab_id)); 76 kNoTabError, base::IntToString(tab_id));
76 return false; 77 return false;
77 } 78 }
78 79
79 // Make sure the URL hasn't changed. 80 // Make sure the URL hasn't changed.
80 NavigationEntry* entry = contents->controller().GetActiveEntry(); 81 NavigationEntry* entry = contents->controller().GetActiveEntry();
81 if (!entry || url != entry->url().spec()) { 82 if (!entry || url != entry->url().spec()) {
82 error_ = ExtensionErrorUtils::FormatErrorMessage(kUrlNotActiveError, url); 83 error_ = ExtensionErrorUtils::FormatErrorMessage(kUrlNotActiveError, url);
83 return false; 84 return false;
84 } 85 }
85 86
86 // Set visibility and broadcast notifications that the UI should be updated. 87 // Set visibility and broadcast notifications that the UI should be updated.
87 page_action->SetIsVisible(tab_id, enable); 88 page_action->SetIsVisible(tab_id, enable);
88 page_action->SetTitle(tab_id, title); 89 page_action->SetTitle(tab_id, title);
89 page_action->SetIconIndex(tab_id, icon_id); 90 page_action->SetIconIndex(tab_id, icon_id);
90 contents->PageActionStateChanged(); 91 contents->tab_contents()->PageActionStateChanged();
91 92
92 return true; 93 return true;
93 } 94 }
94 95
95 bool PageActionFunction::InitCommon(int tab_id) { 96 bool PageActionFunction::InitCommon(int tab_id) {
96 page_action_ = GetExtension()->page_action(); 97 page_action_ = GetExtension()->page_action();
97 if (!page_action_) { 98 if (!page_action_) {
98 error_ = kNoPageActionError; 99 error_ = kNoPageActionError;
99 return false; 100 return false;
100 } 101 }
101 102
102 // Find the TabContents that contains this tab id. 103 // Find the TabContents that contains this tab id.
103 contents_ = NULL; 104 contents_ = NULL;
105 TabContentsWrapper* wrapper = NULL;
104 bool result = ExtensionTabUtil::GetTabById( 106 bool result = ExtensionTabUtil::GetTabById(
105 tab_id, profile(), include_incognito(), NULL, NULL, &contents_, NULL); 107 tab_id, profile(), include_incognito(), NULL, NULL, &wrapper, NULL);
106 if (!result || !contents_) { 108 if (!result || !wrapper) {
107 error_ = ExtensionErrorUtils::FormatErrorMessage( 109 error_ = ExtensionErrorUtils::FormatErrorMessage(
108 kNoTabError, base::IntToString(tab_id)); 110 kNoTabError, base::IntToString(tab_id));
109 return false; 111 return false;
110 } 112 }
113 contents_ = wrapper->tab_contents();
111 114
112 return true; 115 return true;
113 } 116 }
114 117
115 bool PageActionFunction::SetVisible(bool visible) { 118 bool PageActionFunction::SetVisible(bool visible) {
116 int tab_id; 119 int tab_id;
117 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); 120 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
118 if (!InitCommon(tab_id)) 121 if (!InitCommon(tab_id))
119 return false; 122 return false;
120 123
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 if (!InitCommon(tab_id)) 281 if (!InitCommon(tab_id))
279 return false; 282 return false;
280 283
281 std::string text; 284 std::string text;
282 EXTENSION_FUNCTION_VALIDATE(args->GetString("text", &text)); 285 EXTENSION_FUNCTION_VALIDATE(args->GetString("text", &text));
283 286
284 page_action_->SetBadgeText(tab_id, text); 287 page_action_->SetBadgeText(tab_id, text);
285 contents_->PageActionStateChanged(); 288 contents_->PageActionStateChanged();
286 return true; 289 return true;
287 } 290 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698