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

Side by Side Diff: chrome/browser/extensions/extension_popup_api.cc

Issue 3129003: remove toolstrips (Closed)
Patch Set: merge Created 10 years, 4 months 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_popup_api.h" 5 #include "chrome/browser/extensions/extension_popup_api.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/extensions/extension_dom_ui.h" 9 #include "chrome/browser/extensions/extension_dom_ui.h"
10 #include "chrome/browser/extensions/extension_host.h" 10 #include "chrome/browser/extensions/extension_host.h"
(...skipping 27 matching lines...) Expand all
38 38
39 } // namespace extension_popup_module_events 39 } // namespace extension_popup_module_events
40 40
41 namespace { 41 namespace {
42 42
43 // Errors. 43 // Errors.
44 const char kBadAnchorArgument[] = "Invalid anchor argument."; 44 const char kBadAnchorArgument[] = "Invalid anchor argument.";
45 const char kInvalidURLError[] = "Invalid URL."; 45 const char kInvalidURLError[] = "Invalid URL.";
46 const char kNotAnExtension[] = "Not an extension view."; 46 const char kNotAnExtension[] = "Not an extension view.";
47 const char kPopupsDisallowed[] = 47 const char kPopupsDisallowed[] =
48 "Popups are only supported from toolstrip or tab-contents views."; 48 "Popups are only supported from tab-contents views.";
49 49
50 // Keys. 50 // Keys.
51 const wchar_t kUrlKey[] = L"url"; 51 const wchar_t kUrlKey[] = L"url";
52 const wchar_t kWidthKey[] = L"width"; 52 const wchar_t kWidthKey[] = L"width";
53 const wchar_t kHeightKey[] = L"height"; 53 const wchar_t kHeightKey[] = L"height";
54 const wchar_t kTopKey[] = L"top"; 54 const wchar_t kTopKey[] = L"top";
55 const wchar_t kLeftKey[] = L"left"; 55 const wchar_t kLeftKey[] = L"left";
56 const wchar_t kGiveFocusKey[] = L"giveFocus"; 56 const wchar_t kGiveFocusKey[] = L"giveFocus";
57 const wchar_t kDomAnchorKey[] = L"domAnchor"; 57 const wchar_t kDomAnchorKey[] = L"domAnchor";
58 const wchar_t kBorderStyleKey[] = L"borderStyle"; 58 const wchar_t kBorderStyleKey[] = L"borderStyle";
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 registrar_.Add(this, NotificationType::EXTENSION_HOST_DESTROYED, 349 registrar_.Add(this, NotificationType::EXTENSION_HOST_DESTROYED,
350 NotificationService::AllSources()); 350 NotificationService::AllSources());
351 } 351 }
352 } 352 }
353 #else 353 #else
354 SendResponse(false); 354 SendResponse(false);
355 #endif 355 #endif
356 } 356 }
357 357
358 bool PopupShowFunction::RunImpl() { 358 bool PopupShowFunction::RunImpl() {
359 // Popups may only be displayed from TAB_CONTENTS and EXTENSION_TOOLSTRIP 359 // Popups may only be displayed from TAB_CONTENTS.
360 // views.
361 ViewType::Type view_type = 360 ViewType::Type view_type =
362 dispatcher()->render_view_host()->delegate()->GetRenderViewType(); 361 dispatcher()->render_view_host()->delegate()->GetRenderViewType();
363 if (ViewType::EXTENSION_TOOLSTRIP != view_type && 362 if (ViewType::TAB_CONTENTS != view_type) {
364 ViewType::TAB_CONTENTS != view_type) {
365 error_ = kPopupsDisallowed; 363 error_ = kPopupsDisallowed;
366 return false; 364 return false;
367 } 365 }
368 366
369 std::string url_string; 367 std::string url_string;
370 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url_string)); 368 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url_string));
371 369
372 DictionaryValue* show_details = NULL; 370 DictionaryValue* show_details = NULL;
373 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &show_details)); 371 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &show_details));
374 372
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 435
438 // Get the correct native window to pass to ExtensionPopup. 436 // Get the correct native window to pass to ExtensionPopup.
439 // ExtensionFunctionDispatcher::Delegate may provide a custom implementation 437 // ExtensionFunctionDispatcher::Delegate may provide a custom implementation
440 // of this. 438 // of this.
441 gfx::NativeWindow window = 439 gfx::NativeWindow window =
442 dispatcher()->delegate()->GetCustomFrameNativeWindow(); 440 dispatcher()->delegate()->GetCustomFrameNativeWindow();
443 if (!window) 441 if (!window)
444 window = GetCurrentBrowser()->window()->GetNativeHandle(); 442 window = GetCurrentBrowser()->window()->GetNativeHandle();
445 443
446 #if defined(TOOLKIT_VIEWS) 444 #if defined(TOOLKIT_VIEWS)
447 // Pop-up from extension views (ExtensionShelf, etc.), and drop-down when 445 BubbleBorder::ArrowLocation arrow_location = BubbleBorder::TOP_LEFT;
448 // in a TabContents view.
449 BubbleBorder::ArrowLocation arrow_location =
450 view_type == ViewType::TAB_CONTENTS ?
451 BubbleBorder::TOP_LEFT : BubbleBorder::BOTTOM_LEFT;
452 446
453 // ExtensionPopupHost manages it's own lifetime. 447 // ExtensionPopupHost manages it's own lifetime.
454 ExtensionPopupHost* popup_host = new ExtensionPopupHost(dispatcher()); 448 ExtensionPopupHost* popup_host = new ExtensionPopupHost(dispatcher());
455 popup_ = ExtensionPopup::Show(url, 449 popup_ = ExtensionPopup::Show(url,
456 GetCurrentBrowser(), 450 GetCurrentBrowser(),
457 dispatcher()->profile(), 451 dispatcher()->profile(),
458 window, 452 window,
459 rect, 453 rect,
460 arrow_location, 454 arrow_location,
461 give_focus, 455 give_focus,
462 false, // inspect_with_devtools 456 false, // inspect_with_devtools
463 chrome, 457 chrome,
464 popup_host); // ExtensionPopup::Observer 458 popup_host); // ExtensionPopup::Observer
465 459
466 // popup_host will handle focus change listening and close the popup when 460 // popup_host will handle focus change listening and close the popup when
467 // focus leaves the containing views hierarchy. 461 // focus leaves the containing views hierarchy.
468 popup_->set_close_on_lost_focus(false); 462 popup_->set_close_on_lost_focus(false);
469 popup_host->set_popup(popup_); 463 popup_host->set_popup(popup_);
470 #endif // defined(TOOLKIT_VIEWS) 464 #endif // defined(TOOLKIT_VIEWS)
465
471 return true; 466 return true;
472 } 467 }
473 468
474 void PopupShowFunction::Observe(NotificationType type, 469 void PopupShowFunction::Observe(NotificationType type,
475 const NotificationSource& source, 470 const NotificationSource& source,
476 const NotificationDetails& details) { 471 const NotificationDetails& details) {
477 #if defined(TOOLKIT_VIEWS) 472 #if defined(TOOLKIT_VIEWS)
478 DCHECK(type == NotificationType::EXTENSION_POPUP_VIEW_READY || 473 DCHECK(type == NotificationType::EXTENSION_POPUP_VIEW_READY ||
479 type == NotificationType::EXTENSION_HOST_DESTROYED); 474 type == NotificationType::EXTENSION_HOST_DESTROYED);
480 DCHECK(popup_ != NULL); 475 DCHECK(popup_ != NULL);
(...skipping 20 matching lines...) Expand all
501 std::string full_event_name = StringPrintf( 496 std::string full_event_name = StringPrintf(
502 extension_popup_module_events::kOnPopupClosed, 497 extension_popup_module_events::kOnPopupClosed,
503 routing_id); 498 routing_id);
504 499
505 profile->GetExtensionMessageService()->DispatchEventToRenderers( 500 profile->GetExtensionMessageService()->DispatchEventToRenderers(
506 full_event_name, 501 full_event_name,
507 base::JSONWriter::kEmptyArray, 502 base::JSONWriter::kEmptyArray,
508 profile->IsOffTheRecord(), 503 profile->IsOffTheRecord(),
509 GURL()); 504 GURL());
510 } 505 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_host.cc ('k') | chrome/browser/extensions/extension_popup_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698