OLD | NEW |
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 #include "chrome/renderer/translate/translate_helper.h" | 5 #include "chrome/renderer/translate/translate_helper.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 TranslateCommonMetrics::ReportPageScheme(url.scheme()); | 350 TranslateCommonMetrics::ReportPageScheme(url.scheme()); |
351 | 351 |
352 // Set up v8 isolated world with proper content-security-policy and | 352 // Set up v8 isolated world with proper content-security-policy and |
353 // security-origin. | 353 // security-origin. |
354 WebFrame* frame = GetMainFrame(); | 354 WebFrame* frame = GetMainFrame(); |
355 if (frame) { | 355 if (frame) { |
356 frame->setIsolatedWorldContentSecurityPolicy( | 356 frame->setIsolatedWorldContentSecurityPolicy( |
357 chrome::ISOLATED_WORLD_ID_TRANSLATE, | 357 chrome::ISOLATED_WORLD_ID_TRANSLATE, |
358 WebString::fromUTF8(kContentSecurityPolicy)); | 358 WebString::fromUTF8(kContentSecurityPolicy)); |
359 | 359 |
| 360 std::string security_origin(kSecurityOrigin); |
| 361 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 362 if (command_line->HasSwitch(switches::kTranslateSecurityOrigin)) { |
| 363 security_origin = |
| 364 command_line->GetSwitchValueASCII(switches::kTranslateSecurityOrigin); |
| 365 } |
360 frame->setIsolatedWorldSecurityOrigin( | 366 frame->setIsolatedWorldSecurityOrigin( |
361 chrome::ISOLATED_WORLD_ID_TRANSLATE, | 367 chrome::ISOLATED_WORLD_ID_TRANSLATE, |
362 WebSecurityOrigin::create(GURL(kSecurityOrigin))); | 368 WebSecurityOrigin::create(GURL(security_origin))); |
363 } | 369 } |
364 | 370 |
365 if (!IsTranslateLibAvailable()) { | 371 if (!IsTranslateLibAvailable()) { |
366 // Evaluate the script to add the translation related method to the global | 372 // Evaluate the script to add the translation related method to the global |
367 // context of the page. | 373 // context of the page. |
368 ExecuteScript(translate_script); | 374 ExecuteScript(translate_script); |
369 DCHECK(IsTranslateLibAvailable()); | 375 DCHECK(IsTranslateLibAvailable()); |
370 } | 376 } |
371 | 377 |
372 TranslatePageImpl(0); | 378 TranslatePageImpl(0); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 498 |
493 WebFrame* TranslateHelper::GetMainFrame() { | 499 WebFrame* TranslateHelper::GetMainFrame() { |
494 WebView* web_view = render_view()->GetWebView(); | 500 WebView* web_view = render_view()->GetWebView(); |
495 | 501 |
496 // When the tab is going to be closed, the web_view can be NULL. | 502 // When the tab is going to be closed, the web_view can be NULL. |
497 if (!web_view) | 503 if (!web_view) |
498 return NULL; | 504 return NULL; |
499 | 505 |
500 return web_view->mainFrame(); | 506 return web_view->mainFrame(); |
501 } | 507 } |
OLD | NEW |