[Release] livebox.web-provider-1.46
[platform/framework/web/web-provider.git] / src / Core / BoxSchemeHandler.cpp
index 17a8ce7..cbacb14 100755 (executable)
@@ -1,11 +1,11 @@
 /*
  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
  *
- *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    Licensed under the Flora License, Version 1.1 (the "License");
  *    you may not use this file except in compliance with the License.
  *    You may obtain a copy of the License at
  *
- *        http://www.apache.org/licenses/LICENSE-2.0
+ *        http://floralicense.org/license/
  *
  *    Unless required by applicable law or agreed to in writing, software
  *    distributed under the License is distributed on an "AS IS" BASIS,
  */
 
 #include <string.h>
+#include <ctime>
 #include "Box.h"
 #include "Service/AppControl.h"
 #include "Service/PeriodChanger.h"
 #include "Service/ScrollHolder.h"
+#include "Service/MessageManager.h"
 #include "Util/Log.h"
 #include "BoxSchemeHandler.h"
 
+using namespace Service;
+
 static const std::string BOX_SCHEME("box://");
 static const std::string BOX_SCHEME_RELOAD("box://reload");
 static const std::string BOX_SCHEME_CHANGE_PERIOD("box://change-period");
 static const std::string BOX_SCHEME_LAUNCH_BROWSER("box://launch-browser");
 static const std::string BOX_SCHEME_SCROLL_START("box://scroll-start");
 static const std::string BOX_SCHEME_SCROLL_STOP("box://scroll-stop");
+static const std::string BOX_SCHEME_SEND_MESSAGE_TO_PD("box://send-message-to-pd");
+static const std::string BOX_SCHEME_SEND_MESSAGE_TO_BOX("box://send-message-to-box");
 
 static const std::string HTTP_SCHEME("http://");
 static const std::string HTTPS_SCHEME("https://");
@@ -122,6 +128,25 @@ bool BoxSchemeHandler::process(std::string& instanceId, std::string& uri)
        return handleScroll(instanceId, false);
     }
 
+    if (!uri.compare(
+                0,
+                BOX_SCHEME_SEND_MESSAGE_TO_BOX.size(),
+                BOX_SCHEME_SEND_MESSAGE_TO_BOX))
+    {
+        std::string key("message");
+        std::string message = parse(uri, key);
+        return handleSendMessage(instanceId, MessageManager::TO_BOX, message);
+    }
+
+    if (!uri.compare(
+                0,
+                BOX_SCHEME_SEND_MESSAGE_TO_PD.size(),
+                BOX_SCHEME_SEND_MESSAGE_TO_PD))
+    {
+        std::string key("message");
+        std::string message = parse(uri, key);
+        return handleSendMessage(instanceId, MessageManager::TO_PD, message);
+    }
     LogD("unknown box scheme protocol");
     return false;
 }
@@ -173,7 +198,8 @@ bool BoxSchemeHandler::handleReload(std::string& instanceId)
         return false;
     }
 
-    box->update();
+    // In the future, new content info can be set by caller
+    box->updateInternal();
     return true;
 }
 
@@ -198,8 +224,8 @@ bool BoxSchemeHandler::handleChangePeriod(std::string& instanceId, float request
 bool BoxSchemeHandler::handleLaunchBrowser(std::string& instanceId, std::string& url)
 {
     LogD("enter");
-    if(!url.compare(0, HTTP_SCHEME.size(), HTTP_SCHEME) ||
-       !url.compare(0, HTTPS_SCHEME.size(), HTTPS_SCHEME))
+    if (!url.compare(0, HTTP_SCHEME.size(), HTTP_SCHEME) ||
+        !url.compare(0, HTTPS_SCHEME.size(), HTTPS_SCHEME))
     {
         return Service::AppControl::launchBrowser(url);
     }
@@ -207,6 +233,35 @@ bool BoxSchemeHandler::handleLaunchBrowser(std::string& instanceId, std::string&
     return false;
 }
 
+bool BoxSchemeHandler::handleSendMessage(
+        std::string& instanceId, 
+        MessageManager::ReceiverType receiver, 
+        std::string& message)
+{
+    LogD("enter");
+    Box* box = getBox(instanceId);
+    if (!box) {
+        LogD("no box for update period");
+        return false;
+    };
+
+    // set webview of receiver
+    Evas_Object* webview;
+    switch (receiver) {
+    case MessageManager::TO_BOX:
+        webview = box->m_view->getBoxWebView();
+        break;
+    case MessageManager::TO_PD:
+        webview = box->m_view->getPdWebView();
+        break;
+    default:
+        LogD("not supported receiver");
+        return false;
+    }
+
+    return m_messageManager->send(webview, receiver, message); 
+}
+
 std::string BoxSchemeHandler::parse(std::string& uri, std::string& key)
 {
     LogD("enter");