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/value_helper.h"
6
7 #include "chrome/browser/ui/webui/new_tab_ui.h"
8 #include "chrome/common/url_constants.h"
9
TabToValue(const TabRestoreService::Tab & tab,DictionaryValue * dictionary)10 bool ValueHelper::TabToValue(
11 const TabRestoreService::Tab& tab,
12 DictionaryValue* dictionary) {
13 if (tab.navigations.empty())
14 return false;
15
16 const TabNavigation& current_navigation =
17 tab.navigations.at(tab.current_navigation_index);
18 if (current_navigation.virtual_url() == GURL(chrome::kChromeUINewTabURL))
19 return false;
20 NewTabUI::SetURLTitleAndDirection(dictionary, current_navigation.title(),
21 current_navigation.virtual_url());
22 dictionary->SetString("type", "tab");
23 dictionary->SetDouble("timestamp", tab.timestamp.ToDoubleT());
24 return true;
25 }
26
WindowToValue(const TabRestoreService::Window & window,DictionaryValue * dictionary)27 bool ValueHelper::WindowToValue(
28 const TabRestoreService::Window& window,
29 DictionaryValue* dictionary) {
30 if (window.tabs.empty()) {
31 NOTREACHED();
32 return false;
33 }
34 scoped_ptr<ListValue> tab_values(new ListValue());
35 for (size_t i = 0; i < window.tabs.size(); ++i) {
36 scoped_ptr<DictionaryValue> tab_value(new DictionaryValue());
37 if (TabToValue(window.tabs[i], tab_value.get()))
38 tab_values->Append(tab_value.release());
39 }
40 if (tab_values->GetSize() == 0)
41 return false;
42 dictionary->SetString("type", "window");
43 dictionary->SetDouble("timestamp", window.timestamp.ToDoubleT());
44 dictionary->Set("tabs", tab_values.release());
45 return true;
46 }
47
48