Commit 2ab4a7c3 authored by spqchan's avatar spqchan Committed by Commit Bot

[Mac] Fix chrome::mac::IsJavaScriptEnabledForProfile crash

Bug: 829298
Change-Id: I24c6fb3fde3ad30f00801e096cd034e16642ce35
Reviewed-on: https://chromium-review.googlesource.com/1048625Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: Sarah Chan <spqchan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557594}
parent f8f05d06
...@@ -102,6 +102,7 @@ NSAppleEventDescriptor* ValueToAppleEventDescriptor(const base::Value* value) { ...@@ -102,6 +102,7 @@ NSAppleEventDescriptor* ValueToAppleEventDescriptor(const base::Value* value) {
} }
bool IsJavaScriptEnabledForProfile(Profile* profile) { bool IsJavaScriptEnabledForProfile(Profile* profile) {
DCHECK(profile);
if (!base::FeatureList::IsEnabled( if (!base::FeatureList::IsEnabled(
features::kAppleScriptExecuteJavaScriptMenuItem)) features::kAppleScriptExecuteJavaScriptMenuItem))
return YES; return YES;
......
...@@ -105,6 +105,7 @@ void ResumeAppleEventAndSendReply(NSAppleEventManagerSuspensionID suspension_id, ...@@ -105,6 +105,7 @@ void ResumeAppleEventAndSendReply(NSAppleEventManagerSuspensionID suspension_id,
webContents_ = webContents; webContents_ = webContents;
SessionTabHelper* session_tab_helper = SessionTabHelper* session_tab_helper =
SessionTabHelper::FromWebContents(webContents); SessionTabHelper::FromWebContents(webContents);
profile_ = Profile::FromBrowserContext(webContents->GetBrowserContext());
base::scoped_nsobject<NSNumber> numID( base::scoped_nsobject<NSNumber> numID(
[[NSNumber alloc] initWithInt:session_tab_helper->session_id().id()]); [[NSNumber alloc] initWithInt:session_tab_helper->session_id().id()]);
[self setUniqueID:numID]; [self setUniqueID:numID];
...@@ -127,6 +128,14 @@ void ResumeAppleEventAndSendReply(NSAppleEventManagerSuspensionID suspension_id, ...@@ -127,6 +128,14 @@ void ResumeAppleEventAndSendReply(NSAppleEventManagerSuspensionID suspension_id,
} }
- (void)setURL:(NSString*)aURL { - (void)setURL:(NSString*)aURL {
// If a scripter sets a URL before |webContents_| or |profile_| is set, save
// it at a temporary location. Once they're set, -setURL: will be call again
// with the temporary URL.
if (!profile_ || !webContents_) {
[self setTempURL:aURL];
return;
}
GURL url(base::SysNSStringToUTF8(aURL)); GURL url(base::SysNSStringToUTF8(aURL));
if (!chrome::mac::IsJavaScriptEnabledForProfile(profile_) && if (!chrome::mac::IsJavaScriptEnabledForProfile(profile_) &&
url.SchemeIs(url::kJavaScriptScheme)) { url.SchemeIs(url::kJavaScriptScheme)) {
...@@ -134,13 +143,6 @@ void ResumeAppleEventAndSendReply(NSAppleEventManagerSuspensionID suspension_id, ...@@ -134,13 +143,6 @@ void ResumeAppleEventAndSendReply(NSAppleEventManagerSuspensionID suspension_id,
return; return;
} }
// If a scripter sets a URL before the node is added save it at a temporary
// location.
if (!webContents_) {
[self setTempURL:aURL];
return;
}
// check for valid url. // check for valid url.
if (!url.is_empty() && !url.is_valid()) { if (!url.is_empty() && !url.is_valid()) {
AppleScript::SetError(AppleScript::errInvalidURL); AppleScript::SetError(AppleScript::errInvalidURL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment