| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_tabs_module.h" | 5 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 | 946 |
| 947 // Close the tab in this convoluted way, since there's a chance that the tab | 947 // Close the tab in this convoluted way, since there's a chance that the tab |
| 948 // is being dragged, or we're in some other nested event loop. This code path | 948 // is being dragged, or we're in some other nested event loop. This code path |
| 949 // should ensure that the tab is safely closed under such circumstances, | 949 // should ensure that the tab is safely closed under such circumstances, |
| 950 // whereas |Browser::CloseTabContents()| does not. | 950 // whereas |Browser::CloseTabContents()| does not. |
| 951 RenderViewHost* render_view_host = contents->render_view_host(); | 951 RenderViewHost* render_view_host = contents->render_view_host(); |
| 952 render_view_host->delegate()->Close(render_view_host); | 952 render_view_host->delegate()->Close(render_view_host); |
| 953 return true; | 953 return true; |
| 954 } | 954 } |
| 955 | 955 |
| 956 bool SetZoomPercentTabFunction::RunImpl() { |
| 957 int tab_id; |
| 958 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); |
| 959 |
| 960 double zoom_percent = 0; |
| 961 if (!args_->GetDouble(1, &zoom_percent)) { |
| 962 int int_zoom_percent = 0; |
| 963 if (!args_->GetInteger(1, &int_zoom_percent)) { |
| 964 bad_message_ = true; |
| 965 return false; |
| 966 } |
| 967 zoom_percent = int_zoom_percent; |
| 968 } |
| 969 |
| 970 // WebKit won't like a negative zoom factor |
| 971 if (zoom_percent < 0) { |
| 972 return false; |
| 973 } |
| 974 |
| 975 Browser* browser = NULL; |
| 976 TabContentsWrapper* contents = NULL; |
| 977 if (!GetTabById(tab_id, profile(), include_incognito(), |
| 978 &browser, NULL, &contents, NULL, &error_)) { |
| 979 return false; |
| 980 } |
| 981 |
| 982 // Store the tab id for later |
| 983 tab_id_ = tab_id; |
| 984 |
| 985 request_id_ = contents->tab_contents()->SetZoomPercent(zoom_percent); |
| 986 |
| 987 // Need to wait until the render process responds to the request |
| 988 // before we can respond to the extension request. |
| 989 registrar_.Add(this, |
| 990 NotificationType::ZOOM_LEVEL_CHANGED, |
| 991 NotificationService::AllSources()); |
| 992 AddRef(); // Balanced in SetZoomPercentTabFunction::Observe(). |
| 993 |
| 994 return true; |
| 995 } |
| 996 |
| 997 void SetZoomPercentTabFunction::Observe(NotificationType type, |
| 998 const NotificationSource& source, |
| 999 const NotificationDetails& details) { |
| 1000 DCHECK(type == NotificationType::ZOOM_LEVEL_CHANGED); |
| 1001 |
| 1002 // Wait for our specific request |
| 1003 int observed_request_id = *Details<int>(details).ptr(); |
| 1004 if (observed_request_id != request_id_) { |
| 1005 return; |
| 1006 } |
| 1007 |
| 1008 registrar_.RemoveAll(); |
| 1009 |
| 1010 Browser* browser = NULL; |
| 1011 TabContentsWrapper* contents = NULL; |
| 1012 if (!GetTabById(tab_id_, profile(), include_incognito(), |
| 1013 &browser, NULL, &contents, NULL, &error_)) { |
| 1014 Release(); // Balanced in SetZoomPercentTabFunction::RunImpl |
| 1015 return; |
| 1016 } |
| 1017 |
| 1018 bool enable_inc_ignored; |
| 1019 bool enable_dec_ignored; |
| 1020 double zoom_percent = contents->tab_contents()->GetZoomPercent( |
| 1021 &enable_inc_ignored, &enable_dec_ignored); |
| 1022 |
| 1023 result_.reset(Value::CreateDoubleValue(zoom_percent)); |
| 1024 SendResponse(true); |
| 1025 Release(); // Balanced in SetZoomPercentTabFunction::RunImpl |
| 1026 } |
| 1027 |
| 1028 bool GetZoomPercentTabFunction::RunImpl() { |
| 1029 int tab_id; |
| 1030 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); |
| 1031 |
| 1032 Browser* browser = NULL; |
| 1033 TabContentsWrapper* contents = NULL; |
| 1034 if (!GetTabById(tab_id, profile(), include_incognito(), |
| 1035 &browser, NULL, &contents, NULL, &error_)) { |
| 1036 return false; |
| 1037 } |
| 1038 |
| 1039 bool enable_inc_ignored; |
| 1040 bool enable_dec_ignored; |
| 1041 double zoom_percent = contents->tab_contents()->GetZoomPercent( |
| 1042 &enable_inc_ignored, &enable_dec_ignored); |
| 1043 |
| 1044 result_.reset(Value::CreateDoubleValue(zoom_percent)); |
| 1045 return true; |
| 1046 } |
| 1047 |
| 956 bool CaptureVisibleTabFunction::RunImpl() { | 1048 bool CaptureVisibleTabFunction::RunImpl() { |
| 957 Browser* browser; | 1049 Browser* browser; |
| 958 // windowId defaults to "current" window. | 1050 // windowId defaults to "current" window. |
| 959 int window_id = -1; | 1051 int window_id = -1; |
| 960 | 1052 |
| 961 if (HasOptionalArgument(0)) { | 1053 if (HasOptionalArgument(0)) { |
| 962 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); | 1054 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); |
| 963 browser = GetBrowserInProfileWithId(profile(), window_id, | 1055 browser = GetBrowserInProfileWithId(profile(), window_id, |
| 964 include_incognito(), &error_); | 1056 include_incognito(), &error_); |
| 965 } else { | 1057 } else { |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1241 } | 1333 } |
| 1242 | 1334 |
| 1243 static GURL ResolvePossiblyRelativeURL(std::string url_string, | 1335 static GURL ResolvePossiblyRelativeURL(std::string url_string, |
| 1244 const Extension* extension) { | 1336 const Extension* extension) { |
| 1245 GURL url = GURL(url_string); | 1337 GURL url = GURL(url_string); |
| 1246 if (!url.is_valid()) | 1338 if (!url.is_valid()) |
| 1247 url = extension->GetResourceURL(url_string); | 1339 url = extension->GetResourceURL(url_string); |
| 1248 | 1340 |
| 1249 return url; | 1341 return url; |
| 1250 } | 1342 } |
| OLD | NEW |