OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/shell/browser/shell.h" | 5 #include "content/shell/browser/shell.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "content/public/browser/context_factory.h" | 9 #include "content/public/browser/context_factory.h" |
10 #include "content/public/browser/render_widget_host_view.h" | 10 #include "content/public/browser/render_widget_host_view.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "ui/views/controls/webview/webview.h" | 31 #include "ui/views/controls/webview/webview.h" |
32 #include "ui/views/layout/fill_layout.h" | 32 #include "ui/views/layout/fill_layout.h" |
33 #include "ui/views/layout/grid_layout.h" | 33 #include "ui/views/layout/grid_layout.h" |
34 #include "ui/views/test/desktop_test_views_delegate.h" | 34 #include "ui/views/test/desktop_test_views_delegate.h" |
35 #include "ui/views/view.h" | 35 #include "ui/views/view.h" |
36 #include "ui/views/widget/widget.h" | 36 #include "ui/views/widget/widget.h" |
37 #include "ui/views/widget/widget_delegate.h" | 37 #include "ui/views/widget/widget_delegate.h" |
38 | 38 |
39 #if defined(OS_CHROMEOS) | 39 #if defined(OS_CHROMEOS) |
40 #include "chromeos/dbus/dbus_thread_manager.h" | 40 #include "chromeos/dbus/dbus_thread_manager.h" |
| 41 #endif |
| 42 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
41 #include "ui/aura/test/test_screen.h" | 43 #include "ui/aura/test/test_screen.h" |
42 #include "ui/wm/test/wm_test_helper.h" | 44 #include "ui/wm/test/wm_test_helper.h" |
43 #else // !defined(OS_CHROMEOS) | 45 #else // !defined(OS_CHROMEOS) && !dfined(OS_ANDROID) |
44 #include "ui/views/widget/desktop_aura/desktop_screen.h" | 46 #include "ui/views/widget/desktop_aura/desktop_screen.h" |
45 #endif | 47 #endif |
46 | 48 |
47 #if defined(OS_WIN) | 49 #if defined(OS_WIN) |
48 #include <fcntl.h> | 50 #include <fcntl.h> |
49 #include <io.h> | 51 #include <io.h> |
50 #endif | 52 #endif |
51 | 53 |
| 54 #if defined(OS_ANDROID) |
| 55 #include "base/run_loop.h" |
| 56 #include "jni/Shell_jni.h" |
| 57 #endif |
| 58 |
| 59 #if defined(OS_ANDROID) |
| 60 using base::android::AttachCurrentThread; |
| 61 #endif |
| 62 |
52 namespace content { | 63 namespace content { |
53 | 64 |
54 namespace { | 65 namespace { |
55 // ViewDelegate implementation for aura content shell | 66 // ViewDelegate implementation for aura content shell |
56 class ShellViewsDelegateAura : public views::DesktopTestViewsDelegate { | 67 class ShellViewsDelegateAura : public views::DesktopTestViewsDelegate { |
57 public: | 68 public: |
58 ShellViewsDelegateAura() : use_transparent_windows_(false) { | 69 ShellViewsDelegateAura() : use_transparent_windows_(false) { |
59 } | 70 } |
60 | 71 |
61 ~ShellViewsDelegateAura() override {} | 72 ~ShellViewsDelegateAura() override {} |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 // Overridden from TextfieldController | 313 // Overridden from TextfieldController |
303 void ContentsChanged(views::Textfield* sender, | 314 void ContentsChanged(views::Textfield* sender, |
304 const base::string16& new_contents) override {} | 315 const base::string16& new_contents) override {} |
305 bool HandleKeyEvent(views::Textfield* sender, | 316 bool HandleKeyEvent(views::Textfield* sender, |
306 const ui::KeyEvent& key_event) override { | 317 const ui::KeyEvent& key_event) override { |
307 if (sender == url_entry_ && key_event.key_code() == ui::VKEY_RETURN) { | 318 if (sender == url_entry_ && key_event.key_code() == ui::VKEY_RETURN) { |
308 std::string text = base::UTF16ToUTF8(url_entry_->text()); | 319 std::string text = base::UTF16ToUTF8(url_entry_->text()); |
309 GURL url(text); | 320 GURL url(text); |
310 if (!url.has_scheme()) { | 321 if (!url.has_scheme()) { |
311 url = GURL(std::string("http://") + std::string(text)); | 322 url = GURL(std::string("http://") + std::string(text)); |
| 323 if (url.is_empty() || !url.is_valid()) |
| 324 return false; |
312 url_entry_->SetText(base::ASCIIToUTF16(url.spec())); | 325 url_entry_->SetText(base::ASCIIToUTF16(url.spec())); |
313 } | 326 } |
314 shell_->LoadURL(url); | 327 shell_->LoadURL(url); |
315 return true; | 328 return true; |
316 } | 329 } |
317 return false; | 330 return false; |
318 } | 331 } |
319 | 332 |
320 // Overridden from ButtonListener | 333 // Overridden from ButtonListener |
321 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 334 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 | 404 |
392 // Contents view contains the web contents view | 405 // Contents view contains the web contents view |
393 View* contents_view_; | 406 View* contents_view_; |
394 views::WebView* web_view_; | 407 views::WebView* web_view_; |
395 | 408 |
396 DISALLOW_COPY_AND_ASSIGN(ShellWindowDelegateView); | 409 DISALLOW_COPY_AND_ASSIGN(ShellWindowDelegateView); |
397 }; | 410 }; |
398 | 411 |
399 } // namespace | 412 } // namespace |
400 | 413 |
401 #if defined(OS_CHROMEOS) | 414 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
402 wm::WMTestHelper* Shell::wm_test_helper_ = NULL; | 415 wm::WMTestHelper* Shell::wm_test_helper_ = NULL; |
403 gfx::Screen* Shell::test_screen_ = NULL; | 416 gfx::Screen* Shell::test_screen_ = NULL; |
404 #endif | 417 #endif |
405 views::ViewsDelegate* Shell::views_delegate_ = NULL; | 418 views::ViewsDelegate* Shell::views_delegate_ = NULL; |
406 | 419 |
407 // static | 420 // static |
| 421 #if defined(OS_ANDROID) |
| 422 bool Shell::Register(JNIEnv* env) { |
| 423 return RegisterNativesImpl(env); |
| 424 } |
| 425 |
| 426 void CloseShell(JNIEnv* env, jclass clazz, jlong shellPtr) { |
| 427 Shell* shell = reinterpret_cast<Shell*>(shellPtr); |
| 428 shell->Close(); |
| 429 } |
| 430 #endif |
| 431 |
408 void Shell::PlatformInitialize(const gfx::Size& default_window_size) { | 432 void Shell::PlatformInitialize(const gfx::Size& default_window_size) { |
| 433 LOG(ERROR) << "Shell::PlatformInitialize"; |
409 #if defined(OS_WIN) | 434 #if defined(OS_WIN) |
410 _setmode(_fileno(stdout), _O_BINARY); | 435 _setmode(_fileno(stdout), _O_BINARY); |
411 _setmode(_fileno(stderr), _O_BINARY); | 436 _setmode(_fileno(stderr), _O_BINARY); |
412 #endif | 437 #endif |
| 438 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
413 #if defined(OS_CHROMEOS) | 439 #if defined(OS_CHROMEOS) |
414 chromeos::DBusThreadManager::Initialize(); | 440 chromeos::DBusThreadManager::Initialize(); |
415 test_screen_ = aura::TestScreen::Create(gfx::Size()); | 441 #endif //OS_CHROMEOS |
416 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_); | 442 // TODO(mfomitchev): We should pick the screen we use on Android. |
| 443 // If we use screen_android, we shouldn't do this. |
| 444 // test_screen_ = aura::TestScreen::Create(gfx::Size()); |
| 445 // gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_); |
417 wm_test_helper_ = new wm::WMTestHelper(default_window_size, | 446 wm_test_helper_ = new wm::WMTestHelper(default_window_size, |
418 GetContextFactory()); | 447 GetContextFactory()); |
419 #else | 448 #else |
420 gfx::Screen::SetScreenInstance( | 449 gfx::Screen::SetScreenInstance( |
421 gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); | 450 gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); |
422 #endif | 451 #endif |
423 views_delegate_ = new ShellViewsDelegateAura(); | 452 views_delegate_ = new ShellViewsDelegateAura(); |
424 } | 453 } |
425 | 454 |
426 void Shell::PlatformExit() { | 455 void Shell::PlatformExit() { |
427 #if defined(OS_CHROMEOS) | 456 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
428 delete wm_test_helper_; | 457 delete wm_test_helper_; |
429 wm_test_helper_ = NULL; | 458 wm_test_helper_ = NULL; |
430 | 459 |
431 delete test_screen_; | 460 delete test_screen_; |
432 test_screen_ = NULL; | 461 test_screen_ = NULL; |
433 #endif | 462 #endif |
434 delete views_delegate_; | 463 delete views_delegate_; |
435 views_delegate_ = NULL; | 464 views_delegate_ = NULL; |
436 delete platform_; | 465 delete platform_; |
437 platform_ = NULL; | 466 platform_ = NULL; |
438 #if defined(OS_CHROMEOS) | 467 #if defined(OS_CHROMEOS) |
439 device::BluetoothAdapterFactory::Shutdown(); | 468 device::BluetoothAdapterFactory::Shutdown(); |
440 chromeos::DBusThreadManager::Shutdown(); | 469 chromeos::DBusThreadManager::Shutdown(); |
441 #endif | 470 #endif |
442 aura::Env::DeleteInstance(); | 471 aura::Env::DeleteInstance(); |
443 } | 472 } |
444 | 473 |
445 void Shell::PlatformCleanUp() { | 474 void Shell::PlatformCleanUp() { |
| 475 #if defined(OS_ANDROID) |
| 476 JNIEnv* env = AttachCurrentThread(); |
| 477 if (java_object_.is_null()) |
| 478 return; |
| 479 Java_Shell_onNativeDestroyed(env, java_object_.obj()); |
| 480 #endif |
446 } | 481 } |
447 | 482 |
448 void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) { | 483 void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) { |
449 if (headless_) | 484 if (headless_) |
450 return; | 485 return; |
451 ShellWindowDelegateView* delegate_view = | 486 ShellWindowDelegateView* delegate_view = |
452 static_cast<ShellWindowDelegateView*>(window_widget_->widget_delegate()); | 487 static_cast<ShellWindowDelegateView*>(window_widget_->widget_delegate()); |
453 if (control == BACK_BUTTON) { | 488 if (control == BACK_BUTTON) { |
454 delegate_view->EnableUIControl(ShellWindowDelegateView::BACK_BUTTON, | 489 delegate_view->EnableUIControl(ShellWindowDelegateView::BACK_BUTTON, |
455 is_enabled); | 490 is_enabled); |
(...skipping 11 matching lines...) Expand all Loading... |
467 return; | 502 return; |
468 ShellWindowDelegateView* delegate_view = | 503 ShellWindowDelegateView* delegate_view = |
469 static_cast<ShellWindowDelegateView*>(window_widget_->widget_delegate()); | 504 static_cast<ShellWindowDelegateView*>(window_widget_->widget_delegate()); |
470 delegate_view->SetAddressBarURL(url); | 505 delegate_view->SetAddressBarURL(url); |
471 } | 506 } |
472 | 507 |
473 void Shell::PlatformSetIsLoading(bool loading) { | 508 void Shell::PlatformSetIsLoading(bool loading) { |
474 } | 509 } |
475 | 510 |
476 void Shell::PlatformCreateWindow(int width, int height) { | 511 void Shell::PlatformCreateWindow(int width, int height) { |
| 512 LOG(ERROR) << "auraclank: Shell::PlatformCreateWindow"; |
477 if (headless_) { | 513 if (headless_) { |
478 content_size_ = gfx::Size(width, height); | 514 content_size_ = gfx::Size(width, height); |
479 if (!platform_) | 515 if (!platform_) |
480 platform_ = new ShellPlatformDataAura(content_size_); | 516 platform_ = new ShellPlatformDataAura(content_size_); |
481 else | 517 else |
482 platform_->ResizeWindow(content_size_); | 518 platform_->ResizeWindow(content_size_); |
483 return; | 519 return; |
484 } | 520 } |
485 #if defined(OS_CHROMEOS) | 521 |
| 522 //TODO(mfomitchev): nested loop waiting for the compositor |
| 523 #if defined(OS_ANDROID) |
| 524 wm_test_helper_->host()->Show(); |
| 525 // LOG(ERROR) << "auraclank: Starting nested message loop"; |
| 526 // aura::Env::GetInstance()->AddObserver(this); |
| 527 // base::RunLoop().RunUntilIdle(); |
| 528 // base::RunLoop run_loop; |
| 529 // quit_closure_ = run_loop.QuitClosure(); |
| 530 // base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
| 531 // base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop); |
| 532 // run_loop.Run(); |
| 533 #endif |
| 534 |
| 535 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
486 window_widget_ = views::Widget::CreateWindowWithContextAndBounds( | 536 window_widget_ = views::Widget::CreateWindowWithContextAndBounds( |
487 new ShellWindowDelegateView(this), | 537 new ShellWindowDelegateView(this), |
488 wm_test_helper_->GetDefaultParent(NULL, NULL, gfx::Rect()), | 538 wm_test_helper_->GetDefaultParent(NULL, NULL, gfx::Rect()), |
489 gfx::Rect(0, 0, width, height)); | 539 gfx::Rect(0, 0, width, height)); |
490 #else | 540 #else |
491 window_widget_ = new views::Widget; | 541 window_widget_ = new views::Widget; |
492 views::Widget::InitParams params; | 542 views::Widget::InitParams params; |
493 params.bounds = gfx::Rect(0, 0, width, height); | 543 params.bounds = gfx::Rect(0, 0, width, height); |
494 params.delegate = new ShellWindowDelegateView(this); | 544 params.delegate = new ShellWindowDelegateView(this); |
495 window_widget_->Init(params); | 545 window_widget_->Init(params); |
496 #endif | 546 #endif |
497 | 547 |
498 content_size_ = gfx::Size(width, height); | 548 content_size_ = gfx::Size(width, height); |
499 | 549 |
500 window_ = window_widget_->GetNativeWindow(); | 550 window_ = window_widget_->GetNativeWindow(); |
501 // Call ShowRootWindow on RootWindow created by WMTestHelper without | 551 // Call ShowRootWindow on RootWindow created by WMTestHelper without |
502 // which XWindow owned by RootWindow doesn't get mapped. | 552 // which XWindow owned by RootWindow doesn't get mapped. |
| 553 //TODO(mfomitchev) |
| 554 #if !defined(OS_ANDROID) |
503 window_->GetHost()->Show(); | 555 window_->GetHost()->Show(); |
| 556 #endif |
504 window_widget_->Show(); | 557 window_widget_->Show(); |
| 558 |
| 559 |
505 } | 560 } |
506 | 561 |
| 562 #if defined(OS_ANDROID) |
| 563 // aura::EnvObserver: |
| 564 void Shell::OnHostInitialized(aura::WindowTreeHost* host) { |
| 565 LOG(ERROR) << "auraclank: Shell::OnHostInitialized!"; |
| 566 // quit_closure_.Run(); |
| 567 aura::Env::GetInstance()->RemoveObserver(this); |
| 568 } |
| 569 #endif |
| 570 |
| 571 |
507 void Shell::PlatformSetContents() { | 572 void Shell::PlatformSetContents() { |
508 if (headless_) { | 573 if (headless_) { |
509 CHECK(platform_); | 574 CHECK(platform_); |
510 aura::Window* content = web_contents_->GetNativeView(); | 575 aura::Window* content = web_contents_->GetNativeView(); |
511 aura::Window* parent = platform_->host()->window(); | 576 aura::Window* parent = platform_->host()->window(); |
512 if (!parent->Contains(content)) { | 577 if (!parent->Contains(content)) { |
513 parent->AddChild(content); | 578 parent->AddChild(content); |
514 content->Show(); | 579 content->Show(); |
515 } | 580 } |
516 content->SetBounds(gfx::Rect(content_size_)); | 581 content->SetBounds(gfx::Rect(content_size_)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 const content::ContextMenuParams& params) { | 613 const content::ContextMenuParams& params) { |
549 if (headless_) | 614 if (headless_) |
550 return true; | 615 return true; |
551 ShellWindowDelegateView* delegate_view = | 616 ShellWindowDelegateView* delegate_view = |
552 static_cast<ShellWindowDelegateView*>(window_widget_->widget_delegate()); | 617 static_cast<ShellWindowDelegateView*>(window_widget_->widget_delegate()); |
553 delegate_view->ShowWebViewContextMenu(params); | 618 delegate_view->ShowWebViewContextMenu(params); |
554 return true; | 619 return true; |
555 } | 620 } |
556 | 621 |
557 } // namespace content | 622 } // namespace content |
OLD | NEW |