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

Unified Diff: chrome/browser/extensions/extension_tabs_module.cc

Issue 6413014: Original patch from issue 570048 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: a few fixes Created 9 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_tabs_module.cc
diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc
index db84232f53ebdd463e653f29ca35634c87ebf1f0..27b4beb2207481d640c19e169389167654deb916 100644
--- a/chrome/browser/extensions/extension_tabs_module.cc
+++ b/chrome/browser/extensions/extension_tabs_module.cc
@@ -953,6 +953,88 @@ bool RemoveTabFunction::RunImpl() {
return true;
}
+bool SetZoomPercentTabFunction::RunImpl() {
+ int tab_id;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
+
+ double zoom_percent = 0;
+ if (!args_->GetDouble(1, &zoom_percent)) {
+ int int_zoom_percent = 0;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &int_zoom_percent));
Aaron Boodman 2011/02/07 09:26:55 The renderer can never legitimately send anything
+ zoom_percent = int_zoom_percent;
+ }
+ EXTENSION_FUNCTION_VALIDATE(zoom_percent >= 0);
Aaron Boodman 2011/02/07 09:26:55 Same here (had to fix a bug in json_schema.js firs
+
+ Browser* browser = NULL;
+ TabContentsWrapper* contents = NULL;
+ if (!GetTabById(tab_id, profile(), include_incognito(),
+ &browser, NULL, &contents, NULL, &error_)) {
+ return false;
+ }
+
+ // Store the tab id for later
+ tab_id_ = tab_id;
+
+ request_id_ = contents->tab_contents()->SetZoomPercent(zoom_percent);
+
+ // Need to wait until the render process responds to the request
+ // before we can respond to the extension request.
+ registrar_.Add(this,
+ NotificationType::ZOOM_LEVEL_CHANGED,
+ NotificationService::AllSources());
+ AddRef(); // Balanced in SetZoomPercentTabFunction::Observe().
+
+ return true;
+}
+
+void SetZoomPercentTabFunction::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ CHECK(type == NotificationType::ZOOM_LEVEL_CHANGED);
Aaron Boodman 2011/02/07 09:26:55 I prefer CHECK to DCHECK since it will generate cr
+
+ // Wait for our specific request
+ int observed_request_id = *Details<int>(details).ptr();
+ if (observed_request_id != request_id_)
+ return;
+
+ Browser* browser = NULL;
+ TabContentsWrapper* contents = NULL;
+ if (!GetTabById(tab_id_, profile(), include_incognito(),
+ &browser, NULL, &contents, NULL, &error_)) {
+ Release(); // Balanced in SetZoomPercentTabFunction::RunImpl
+ return;
+ }
+
+ bool enable_inc_ignored = false;
+ bool enable_dec_ignored = false;
+ double zoom_percent = contents->tab_contents()->GetZoomPercent(
+ &enable_inc_ignored, &enable_dec_ignored);
+
+ result_.reset(Value::CreateDoubleValue(zoom_percent));
+ SendResponse(true);
+ Release(); // Balanced in SetZoomPercentTabFunction::RunImpl
+}
+
+bool GetZoomPercentTabFunction::RunImpl() {
+ int tab_id;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
+
+ Browser* browser = NULL;
+ TabContentsWrapper* contents = NULL;
+ if (!GetTabById(tab_id, profile(), include_incognito(),
+ &browser, NULL, &contents, NULL, &error_)) {
+ return false;
+ }
+
+ bool enable_inc_ignored;
+ bool enable_dec_ignored;
+ double zoom_percent = contents->tab_contents()->GetZoomPercent(
+ &enable_inc_ignored, &enable_dec_ignored);
+
+ result_.reset(Value::CreateDoubleValue(zoom_percent));
+ return true;
+}
+
bool CaptureVisibleTabFunction::RunImpl() {
Browser* browser;
// windowId defaults to "current" window.

Powered by Google App Engine
This is Rietveld 408576698