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

Side by Side Diff: chrome/browser/ui/cocoa/applescript/tab_applescript.mm

Issue 2477633003: [Mac] Add a feature flag to disable Javascript execution in Applescript (Closed)
Patch Set: nit Created 4 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
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 #import "chrome/browser/ui/cocoa/applescript/tab_applescript.h" 5 #import "chrome/browser/ui/cocoa/applescript/tab_applescript.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #import "base/mac/scoped_nsobject.h" 10 #import "base/mac/scoped_nsobject.h"
11 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 #include "chrome/browser/printing/print_view_manager.h" 12 #include "chrome/browser/printing/print_view_manager.h"
13 #include "chrome/browser/sessions/session_tab_helper.h" 13 #include "chrome/browser/sessions/session_tab_helper.h"
14 #include "chrome/browser/ui/cocoa/applescript/apple_event_util.h" 14 #include "chrome/browser/ui/cocoa/applescript/apple_event_util.h"
15 #include "chrome/browser/ui/cocoa/applescript/error_applescript.h" 15 #include "chrome/browser/ui/cocoa/applescript/error_applescript.h"
16 #include "chrome/browser/ui/cocoa/applescript/metrics_applescript.h" 16 #include "chrome/browser/ui/cocoa/applescript/metrics_applescript.h"
17 #include "chrome/common/chrome_features.h"
17 #include "chrome/common/chrome_isolated_world_ids.h" 18 #include "chrome/common/chrome_isolated_world_ids.h"
18 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
19 #include "components/sessions/core/session_id.h" 20 #include "components/sessions/core/session_id.h"
20 #include "content/public/browser/navigation_controller.h" 21 #include "content/public/browser/navigation_controller.h"
21 #include "content/public/browser/navigation_entry.h" 22 #include "content/public/browser/navigation_entry.h"
22 #include "content/public/browser/render_frame_host.h" 23 #include "content/public/browser/render_frame_host.h"
23 #include "content/public/browser/render_view_host.h" 24 #include "content/public/browser/render_view_host.h"
24 #include "content/public/browser/save_page_type.h" 25 #include "content/public/browser/save_page_type.h"
25 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
26 #include "content/public/browser/web_contents_delegate.h" 27 #include "content/public/browser/web_contents_delegate.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 120
120 NavigationEntry* entry = webContents_->GetController().GetActiveEntry(); 121 NavigationEntry* entry = webContents_->GetController().GetActiveEntry();
121 if (!entry) { 122 if (!entry) {
122 return nil; 123 return nil;
123 } 124 }
124 const GURL& url = entry->GetVirtualURL(); 125 const GURL& url = entry->GetVirtualURL();
125 return base::SysUTF8ToNSString(url.spec()); 126 return base::SysUTF8ToNSString(url.spec());
126 } 127 }
127 128
128 - (void)setURL:(NSString*)aURL { 129 - (void)setURL:(NSString*)aURL {
130 GURL url(base::SysNSStringToUTF8(aURL));
131 if (!base::FeatureList::IsEnabled(features::kAppleScriptExecuteJavaScript) &&
132 url.SchemeIs(url::kJavaScriptScheme)) {
133 AppleScript::SetError(AppleScript::errJavaScriptUnsupported);
134 return;
135 }
136
129 // If a scripter sets a URL before the node is added save it at a temporary 137 // If a scripter sets a URL before the node is added save it at a temporary
130 // location. 138 // location.
131 if (!webContents_) { 139 if (!webContents_) {
132 [self setTempURL:aURL]; 140 [self setTempURL:aURL];
133 return; 141 return;
134 } 142 }
135 143
136 GURL url(base::SysNSStringToUTF8(aURL));
137 // check for valid url. 144 // check for valid url.
138 if (!url.is_empty() && !url.is_valid()) { 145 if (!url.is_empty() && !url.is_valid()) {
139 AppleScript::SetError(AppleScript::errInvalidURL); 146 AppleScript::SetError(AppleScript::errInvalidURL);
140 return; 147 return;
141 } 148 }
142 149
143 NavigationEntry* entry = webContents_->GetController().GetActiveEntry(); 150 NavigationEntry* entry = webContents_->GetController().GetActiveEntry();
144 if (!entry) 151 if (!entry)
145 return; 152 return;
146 153
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 if (entry) { 287 if (entry) {
281 webContents_->OpenURL( 288 webContents_->OpenURL(
282 OpenURLParams(GURL(content::kViewSourceScheme + std::string(":") + 289 OpenURLParams(GURL(content::kViewSourceScheme + std::string(":") +
283 entry->GetURL().spec()), 290 entry->GetURL().spec()),
284 Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, 291 Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB,
285 ui::PAGE_TRANSITION_LINK, false)); 292 ui::PAGE_TRANSITION_LINK, false));
286 } 293 }
287 } 294 }
288 295
289 - (id)handlesExecuteJavascriptScriptCommand:(NSScriptCommand*)command { 296 - (id)handlesExecuteJavascriptScriptCommand:(NSScriptCommand*)command {
297 if (!base::FeatureList::IsEnabled(features::kAppleScriptExecuteJavaScript)) {
298 AppleScript::SetError(AppleScript::errJavaScriptUnsupported);
299 return nil;
300 }
301
290 AppleScript::LogAppleScriptUMA( 302 AppleScript::LogAppleScriptUMA(
291 AppleScript::AppleScriptCommand::TAB_EXECUTE_JAVASCRIPT); 303 AppleScript::AppleScriptCommand::TAB_EXECUTE_JAVASCRIPT);
292 content::RenderFrameHost* frame = webContents_->GetMainFrame(); 304 content::RenderFrameHost* frame = webContents_->GetMainFrame();
293 if (!frame) { 305 if (!frame) {
294 NOTREACHED(); 306 NOTREACHED();
295 return nil; 307 return nil;
296 } 308 }
297 309
298 NSAppleEventManager* manager = [NSAppleEventManager sharedAppleEventManager]; 310 NSAppleEventManager* manager = [NSAppleEventManager sharedAppleEventManager];
299 NSAppleEventManagerSuspensionID suspensionID = 311 NSAppleEventManagerSuspensionID suspensionID =
300 [manager suspendCurrentAppleEvent]; 312 [manager suspendCurrentAppleEvent];
301 content::RenderFrameHost::JavaScriptResultCallback callback = 313 content::RenderFrameHost::JavaScriptResultCallback callback =
302 base::Bind(&ResumeAppleEventAndSendReply, suspensionID); 314 base::Bind(&ResumeAppleEventAndSendReply, suspensionID);
303 315
304 base::string16 script = base::SysNSStringToUTF16( 316 base::string16 script = base::SysNSStringToUTF16(
305 [[command evaluatedArguments] objectForKey:@"javascript"]); 317 [[command evaluatedArguments] objectForKey:@"javascript"]);
306 frame->ExecuteJavaScriptInIsolatedWorld( 318 frame->ExecuteJavaScriptInIsolatedWorld(
307 script, callback, chrome::ISOLATED_WORLD_ID_APPLESCRIPT); 319 script, callback, chrome::ISOLATED_WORLD_ID_APPLESCRIPT);
308 320
309 return nil; 321 return nil;
310 } 322 }
311 323
312 @end 324 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/applescript/error_applescript.mm ('k') | chrome/common/chrome_features.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698