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 <string> | |
mazda
2011/11/10 06:03:46
Unnecessary?
yoshiki
2011/11/10 07:54:38
Done.
| |
8 | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "chrome/browser/ui/browser.h" | |
11 #include "chrome/browser/ui/browser_list.h" | |
12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | |
13 #include "chrome/browser/ui/views/extensions/extension_dialog.h" | |
14 #include "chrome/browser/ui/views/extensions/extension_dialog_observer.h" | |
15 #include "grit/generated_resources.h" | |
16 #include "ui/base/l10n/l10n_util.h" | |
17 | |
18 const char* kBookmarkAllTabsURL = | |
19 "chrome-extension://" | |
20 "eemcgdkfndhakfknompkggombfjjjeno/" | |
21 "bookmark_all_tabs.html"; | |
22 | |
23 const int kDialogWidth = 640; | |
24 const int kDialogHeight = 480; | |
25 | |
26 // **************************************************** | |
27 // BookmarkAllTabsDialogBuilder class | |
28 | |
29 class BookmarkAllTabsDialogBuilder : public ExtensionDialogObserver { | |
30 public: | |
31 explicit BookmarkAllTabsDialogBuilder(Profile* profile); | |
32 virtual ~BookmarkAllTabsDialogBuilder(); | |
33 | |
34 // ExtensionDialog::Observer implementation. | |
35 virtual void ExtensionDialogIsClosing(ExtensionDialog* dialog); | |
36 | |
37 void Show(); | |
38 | |
39 private: | |
40 Profile* profile_; | |
41 | |
42 // Host for the extension that implements this dialog. | |
43 scoped_refptr<ExtensionDialog> extension_dialog_; | |
44 | |
45 DISALLOW_COPY_AND_ASSIGN(BookmarkAllTabsDialogBuilder); | |
46 }; | |
47 | |
48 BookmarkAllTabsDialogBuilder::BookmarkAllTabsDialogBuilder(Profile* profile) | |
49 : profile_(profile) { | |
50 } | |
51 | |
52 BookmarkAllTabsDialogBuilder::~BookmarkAllTabsDialogBuilder() { | |
53 if (extension_dialog_) | |
54 extension_dialog_->ObserverDestroyed(); | |
55 } | |
56 | |
57 void BookmarkAllTabsDialogBuilder::ExtensionDialogIsClosing( | |
58 ExtensionDialog* dialog) { | |
59 extension_dialog_ = NULL; | |
60 delete this; | |
61 } | |
62 | |
63 void BookmarkAllTabsDialogBuilder::Show() { | |
64 // Extension background pages may not supply an owner_window. | |
65 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); | |
66 if (!browser) { | |
67 LOG(ERROR) << "Can't find owning browser"; | |
68 return; | |
69 } | |
70 GURL url(kBookmarkAllTabsURL); | |
71 TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper(); | |
72 | |
73 string16 title = | |
74 l10n_util::GetStringUTF16(IDS_BOOKMARK_MANAGER_BOOKMARK_ALL_TABS); | |
75 | |
76 ExtensionDialog* dialog = ExtensionDialog::Show( | |
77 url, | |
78 browser, tab->tab_contents(), | |
79 kDialogWidth, kDialogHeight, | |
80 title, | |
81 this ); | |
82 if (!dialog) { | |
83 LOG(ERROR) << "Unable to create extension dialog"; | |
84 return; | |
85 } | |
86 extension_dialog_ = dialog; | |
87 } | |
88 | |
89 // **************************************************** | |
90 // BookmarkAllTabsDialog class | |
91 | |
92 // static | |
93 void BookmarkAllTabsDialog::Show(Profile* profile) { | |
94 BookmarkAllTabsDialogBuilder *dialog | |
95 = new BookmarkAllTabsDialogBuilder(profile); | |
96 dialog->Show(); | |
97 } | |
98 | |
OLD | NEW |