OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/chromeos/dom_ui/menu_ui.h" | 5 #include "chrome/browser/chromeos/dom_ui/menu_ui.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/singleton.h" | 13 #include "base/singleton.h" |
14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
15 #include "base/string_piece.h" | 15 #include "base/string_piece.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "base/weak_ptr.h" | 18 #include "base/weak_ptr.h" |
19 #include "chrome/browser/browser_thread.h" | 19 #include "chrome/browser/browser_thread.h" |
20 #include "chrome/browser/chromeos/views/native_menu_webui.h" | 20 #include "chrome/browser/chromeos/views/native_menu_webui.h" |
21 #include "chrome/browser/chromeos/views/webui_menu_widget.h" | 21 #include "chrome/browser/chromeos/views/webui_menu_widget.h" |
22 #include "chrome/browser/dom_ui/web_ui_util.h" | 22 #include "chrome/browser/dom_ui/web_ui_util.h" |
| 23 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/tab_contents/tab_contents.h" | 24 #include "chrome/browser/tab_contents/tab_contents.h" |
24 #include "chrome/browser/tab_contents/tab_contents_delegate.h" | 25 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
25 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
26 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/jstemplate_builder.h" | 28 #include "chrome/common/jstemplate_builder.h" |
28 #include "grit/app_resources.h" | 29 #include "grit/app_resources.h" |
29 #include "grit/browser_resources.h" | 30 #include "grit/browser_resources.h" |
30 #include "ui/base/models/menu_model.h" | 31 #include "ui/base/models/menu_model.h" |
31 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
32 #include "ui/gfx/canvas_skia.h" | 33 #include "ui/gfx/canvas_skia.h" |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 //////////////////////////////////////////////////////////////////////////////// | 525 //////////////////////////////////////////////////////////////////////////////// |
525 // | 526 // |
526 // MenuUI | 527 // MenuUI |
527 // | 528 // |
528 //////////////////////////////////////////////////////////////////////////////// | 529 //////////////////////////////////////////////////////////////////////////////// |
529 | 530 |
530 MenuUI::MenuUI(TabContents* contents) : DOMUI(contents) { | 531 MenuUI::MenuUI(TabContents* contents) : DOMUI(contents) { |
531 MenuHandler* handler = new MenuHandler(); | 532 MenuHandler* handler = new MenuHandler(); |
532 AddMessageHandler((handler)->Attach(this)); | 533 AddMessageHandler((handler)->Attach(this)); |
533 | 534 |
534 BrowserThread::PostTask( | 535 contents->profile()->GetChromeURLDataManager()->AddDataSource( |
535 BrowserThread::IO, FROM_HERE, | 536 CreateDataSource()); |
536 NewRunnableMethod( | |
537 ChromeURLDataManager::GetInstance(), | |
538 &ChromeURLDataManager::AddDataSource, | |
539 make_scoped_refptr(CreateDataSource()))); | |
540 } | 537 } |
541 | 538 |
542 MenuUI::MenuUI(TabContents* contents, ChromeURLDataManager::DataSource* source) | 539 MenuUI::MenuUI(TabContents* contents, ChromeURLDataManager::DataSource* source) |
543 : DOMUI(contents) { | 540 : DOMUI(contents) { |
544 MenuHandler* handler = new MenuHandler(); | 541 MenuHandler* handler = new MenuHandler(); |
545 AddMessageHandler((handler)->Attach(this)); | 542 AddMessageHandler((handler)->Attach(this)); |
546 | 543 |
547 BrowserThread::PostTask( | 544 contents->profile()->GetChromeURLDataManager()->AddDataSource(source); |
548 BrowserThread::IO, FROM_HERE, | |
549 NewRunnableMethod( | |
550 ChromeURLDataManager::GetInstance(), | |
551 &ChromeURLDataManager::AddDataSource, | |
552 make_scoped_refptr(source))); | |
553 } | 545 } |
554 | 546 |
555 void MenuUI::ModelUpdated(const ui::MenuModel* model) { | 547 void MenuUI::ModelUpdated(const ui::MenuModel* model) { |
556 DictionaryValue json_model; | 548 DictionaryValue json_model; |
557 ListValue* items = new ListValue(); | 549 ListValue* items = new ListValue(); |
558 json_model.Set("items", items); | 550 json_model.Set("items", items); |
559 int max_icon_width = 0; | 551 int max_icon_width = 0; |
560 bool has_accelerator = false; | 552 bool has_accelerator = false; |
561 for (int index = 0; index < model->GetItemCount(); ++index) { | 553 for (int index = 0; index < model->GetItemCount(); ++index) { |
562 ui::MenuModel::ItemType type = model->GetTypeAt(index); | 554 ui::MenuModel::ItemType type = model->GetTypeAt(index); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 | 646 |
655 ChromeURLDataManager::DataSource* MenuUI::CreateDataSource() { | 647 ChromeURLDataManager::DataSource* MenuUI::CreateDataSource() { |
656 return CreateMenuUIHTMLSource(NULL, | 648 return CreateMenuUIHTMLSource(NULL, |
657 chrome::kChromeUIMenu, | 649 chrome::kChromeUIMenu, |
658 "Menu" /* class name */, | 650 "Menu" /* class name */, |
659 kNoExtraResource, | 651 kNoExtraResource, |
660 kNoExtraResource); | 652 kNoExtraResource); |
661 } | 653 } |
662 | 654 |
663 } // namespace chromeos | 655 } // namespace chromeos |
OLD | NEW |