OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/webui/bookmark_all_tabs_dialog.h" |
| 6 |
| 7 #include "base/compiler_specific.h" |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_list.h" |
| 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 12 #include "chrome/browser/ui/views/extensions/extension_dialog.h" |
| 13 #include "chrome/browser/ui/views/extensions/extension_dialog_observer.h" |
| 14 #include "grit/generated_resources.h" |
| 15 #include "ui/base/l10n/l10n_util.h" |
| 16 |
| 17 const char kBookmarkAllTabsURL[] = |
| 18 "chrome-extension://eemcgdkfndhakfknompkggombfjjjeno/" |
| 19 "bookmark_all_tabs.html"; |
| 20 |
| 21 const int kDialogWidth = 640; |
| 22 const int kDialogHeight = 480; |
| 23 |
| 24 //////////////////////////////////////////////////////////////////////////////// |
| 25 // BookmarkAllTabsDialogBuilder class |
| 26 //////////////////////////////////////////////////////////////////////////////// |
| 27 |
| 28 class BookmarkAllTabsDialogBuilder : public ExtensionDialogObserver { |
| 29 public: |
| 30 explicit BookmarkAllTabsDialogBuilder(Profile* profile); |
| 31 virtual ~BookmarkAllTabsDialogBuilder(); |
| 32 |
| 33 // ExtensionDialog::Observer implementation. |
| 34 virtual void ExtensionDialogIsClosing(ExtensionDialog* dialog) OVERRIDE; |
| 35 |
| 36 void Show(); |
| 37 |
| 38 private: |
| 39 Profile* profile_; |
| 40 |
| 41 // Host for the extension that implements this dialog. |
| 42 scoped_refptr<ExtensionDialog> extension_dialog_; |
| 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(BookmarkAllTabsDialogBuilder); |
| 45 }; |
| 46 |
| 47 BookmarkAllTabsDialogBuilder::BookmarkAllTabsDialogBuilder(Profile* profile) |
| 48 : profile_(profile) { |
| 49 } |
| 50 |
| 51 BookmarkAllTabsDialogBuilder::~BookmarkAllTabsDialogBuilder() { |
| 52 if (extension_dialog_) |
| 53 extension_dialog_->ObserverDestroyed(); |
| 54 } |
| 55 |
| 56 void BookmarkAllTabsDialogBuilder::ExtensionDialogIsClosing( |
| 57 ExtensionDialog* dialog) { |
| 58 extension_dialog_ = NULL; |
| 59 delete this; |
| 60 } |
| 61 |
| 62 void BookmarkAllTabsDialogBuilder::Show() { |
| 63 // Extension background pages may not supply an owner_window. |
| 64 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); |
| 65 if (!browser) { |
| 66 LOG(ERROR) << "Can't find owning browser"; |
| 67 return; |
| 68 } |
| 69 GURL url(kBookmarkAllTabsURL); |
| 70 TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper(); |
| 71 |
| 72 string16 title = |
| 73 l10n_util::GetStringUTF16(IDS_BOOKMARK_MANAGER_BOOKMARK_ALL_TABS); |
| 74 |
| 75 ExtensionDialog* dialog = ExtensionDialog::Show( |
| 76 url, |
| 77 browser, tab->tab_contents(), |
| 78 kDialogWidth, kDialogHeight, |
| 79 title, |
| 80 this ); |
| 81 if (!dialog) { |
| 82 LOG(ERROR) << "Unable to create extension dialog"; |
| 83 return; |
| 84 } |
| 85 extension_dialog_ = dialog; |
| 86 } |
| 87 |
| 88 namespace browser { |
| 89 |
| 90 void ShowBookmarkAllTabsDialog(Profile* profile) { |
| 91 BookmarkAllTabsDialogBuilder *dialog |
| 92 = new BookmarkAllTabsDialogBuilder(profile); |
| 93 dialog->Show(); |
| 94 } |
| 95 |
| 96 } // namespace browser |
OLD | NEW |