Home | History | Annotate | Download | only in webui
      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 #ifndef CHROME_BROWSER_UI_WEBUI_FOREIGN_SESSION_HANDLER_H_
      6 #define CHROME_BROWSER_UI_WEBUI_FOREIGN_SESSION_HANDLER_H_
      7 #pragma once
      8 
      9 #include <vector>
     10 
     11 #include "chrome/browser/sessions/session_service.h"
     12 #include "chrome/browser/sync/glue/session_model_associator.h"
     13 #include "content/browser/webui/web_ui.h"
     14 #include "content/common/notification_observer.h"
     15 #include "content/common/notification_registrar.h"
     16 
     17 namespace browser_sync {
     18 
     19 class ForeignSessionHandler : public WebUIMessageHandler,
     20                               public NotificationObserver {
     21  public:
     22   // WebUIMessageHandler implementation.
     23   virtual void RegisterMessages();
     24 
     25   ForeignSessionHandler();
     26   virtual ~ForeignSessionHandler() {}
     27 
     28  private:
     29   // Used to register ForeignSessionHandler for notifications.
     30   void Init();
     31 
     32   // Determines how ForeignSessionHandler will interact with the new tab page.
     33   virtual void Observe(NotificationType type,
     34                        const NotificationSource& source,
     35                        const NotificationDetails& details);
     36 
     37   // Returns a pointer to the current session model associator or NULL.
     38   SessionModelAssociator* GetModelAssociator();
     39 
     40   // Determines which session is to be opened, and then calls
     41   // OpenForeignSession, to begin the process of opening a new browser window.
     42   // This is a javascript callback handler.
     43   void HandleOpenForeignSession(const ListValue* args);
     44 
     45   // Determines whether foreign sessions should be obtained from the sync model.
     46   // This is a javascript callback handler, and it is also called when the sync
     47   // model has changed and the new tab page needs to reflect the changes.
     48   void HandleGetForeignSessions(const ListValue* args);
     49 
     50   // Helper methods to create JSON compatible objects from Session objects.
     51   bool SessionTabToValue(const SessionTab& tab, DictionaryValue* dictionary);
     52   bool SessionWindowToValue(const SessionWindow& window,
     53                             DictionaryValue* dictionary);
     54 
     55   // The Registrar used to register ForeignSessionHandler for notifications.
     56   NotificationRegistrar registrar_;
     57 
     58   DISALLOW_COPY_AND_ASSIGN(ForeignSessionHandler);
     59 };
     60 
     61 }  // namespace browser_sync
     62 
     63 #endif  // CHROME_BROWSER_UI_WEBUI_FOREIGN_SESSION_HANDLER_H_
     64